hey all ![]()
I’m making a side scroller currently and I have just written part of my character controller script. I’ll quickly give a rundown on how it all currently works:
Left and right movement uses the classic GetAxis method: (In FixedUpdate())
var translation = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
transform.Translate(translation, 0, 0);
and Jumping:
if (canJump)
{
if (Input.GetKeyDown("space") || Input.GetKeyDown("w"))
rigidbody.AddForce (Vector3.up * jumpForce);
}
So as you can see my character - currently just a capsule - has a rigidbody component. it also has a box collider. Freeze rotation is enabled.
Now I don’t want my character to be bouncy as it lands on the ground after jumping so I added a physic material with dynamic friction and static friction set to 1, and bouncyness set to 0.
The ground itself is a terrain which has the same physic material as the character.
Now the problem:
When I start the game, my character which I placed initially above the ground is affected by gravity and lands on the ground. When it lands on the ground its Z value which is initially 0 changes itself to a very small value like 0.00068. As I walk around in the level it gets larger no matter what direction I go. Eventually the value gets large enough and my character falls off the ground.
Why is this happening? How can I stop it? ![]()
A curious observation: If I set dynamic and static friction to 0 the problem doesn’t happen. Z stays 0 the whole time, which is great, but since the friction is 0 my character would very slowly slide across the ground after moving and seem to never stop.