2D Platformer: Character is bumpy on slopes

Hello,

I am trying to code a 2D Platformer starting from the example available on the asset store.

I have a little problem: When the character is moving on slopes it has a bumpy behavior (it does not stick to the ground).
I think that’s because a force is applied to the character on the x axis (depending on the joystick input) while the physics and gravity determines what happens on the y axis.

// code from Unity example
float h = Input.GetAxis(“Horizontal”);
rigidbody2D.AddForce(Vector2.right * h * moveDefaultForce);

Does somenone know how to fix this little problem?

Thanks.

It’s actually a bit of a big problem. The quick and dirty way is to use a sphere collider, but that still doesn’t give good results, and still won’t handle downslopes properly. The best and simplest way I’ve found is to do a raycast to the ground, get the hit.normal, and then use that normal (with a little math) to determine how to move the player along the surface. You’ll hug up and down slopes without catching air.

Thank you very very much for your replay.

I will definitively try out your solution when I have time.

I tweaked the physics properties to get an acceptable result, but this is something I will definitively have to polish later.

Thanks again!

You could also purchase This

it handles slopes beautifully.