# Issues using physics for 2d platformer.

I have looked at many questions about the best way to control movement of a character in a 2d platform game and still can’t find a decent answer. Also, none of them address the main problem I have which is that when I walk/run into a slope, not only does it let me go up very steep slopes, but it adds upwards force, and the character shoots up very far without jumping. This is the same if you just about make a platform when jumping to it and hit the edge.

I am using rigidbody2d.velocity = new Vector2 (move * maxSpeed, rb2d.velocity.y); for left and right movement, as suggested in a unity tutorial.

What is the best way to get round this, or, is there a better way to move the player?

Thanks for the support unity. I ended up using this tutorial with a few tweeks if anyone else is wondering 2D Platformer Controller (Unity 5) - YouTube

I don’t have slopes on my game but I can understand why your character would become very fast:
You are adding speed on the x axis regardless of the slope angle. Therefore it is trying to travel the same distance on the x axis as usual, but it needs to go faster as the actual distance is longer. The actual distance is “1 / cos(slope angle)” times the distance on a flat platform. From this formula you can see that if the slope angle is 0 then there is no change (cos(0) = 1), but the bigger the slope angle the greater the distance (and it explodes when the slope angle is 90 obviously as cos(90) = 0).

So you may want to do `move * maxSpeed * Mathf.cos(slopeAngle)` when your character in on a slope (or all the time if you consider that a flat platform is a slope of 0 degree).

You should multiply move * maxSpeed by the cosinus of your slope angle to prevent your character from going faster on the slopes.

Indeed without the cosinus your character is trying to travel the same horizontal distance regardless of the slope angle. Therefore the steeper the slope the faster it has to go.