3

I would like to know if there is any known solution for handling the player's movement on slopes using Box2D engine.

I tried to do it using a circle as the player. Everything was fine until I tried to walk on slopes, the main problem is that due to gravity, the circle does not stop on the slope.

Please if somebody has tried this before I'll appreciate it. If you have a better solution without the physics engine would be fine for me too.

Thank you.

songokuhd
  • 51
  • 3

2 Answers2

2

Behind boxboy by Robert Dodd describes a very sensible method for making a character in box2d that plays like a more traditional platformer character.

The main components is the anglejoint as well as a fixed speed motor joint. With enough friction your character will not slide down slopes, and as long as the motor is active it would keep it from rolling downhill. I'm uncertain exactly how, but you should be able to keep the motor engaged even when its not rotating, to prevent the circle from rolling freely.

Daniel Carlsson
  • 2,371
  • 12
  • 17
-1

You could raycast to judge whether the character is standing on a slope and modify their velocity accordingly.

Anko
  • 13,393
  • 10
  • 54
  • 82