1
\$\begingroup\$

Ive seen alot of pages talking about how to emulate a platformer on Box2D, specially about how people dont want to slide down a slope. Well, my problem is different and Im surprised I cant find posts/solutions about it.

The problem happens when I have a very steep slope and I run against it. This is what happens:

enter image description here

Being the square a common platformer hero fixture, since in a Box2D platformer the movement is based on applying impulses or setting the velocity, what happens when I "move" torwards such a slope, its like im pushing against it, which creates a vertical force and therefore the square moves UP (specially since friction is 0 to avoid the "sticking to a wall" thing).

I've solved most of Box2D's non-platformer-proficient issues. This one seems unsolveable.

So, how do I avoid my object to go up a steep slope when pushed against it, and instead slide down since its too steep to be climbed?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think you are approaching this the wrong way. Box2D is doing exactly what you want it to do, the problem may be with what you want. I assume you are applying gravity? If the force of gravity is less than the upward velocity from your character running against the slope, you are probably applying too much force (or too little gravity) while making your character run. Try adjusting the mass of your character and the strength of forces being applied to it.

Also, if you do not want your character to run up a slope, maybe he should not be running? Maybe it is your design that should change, not the physics. However, it is hard to tell since your question mentions little about the game design. If you want him to stop running while the player is giving the input that the character should be running into a steep slope, one solution is to put a sensor in front of the character that will slow or stop his forward velocity. Sensors for exactly this type of thing are a built-in part of Box2D.

Edit: Another suggestion is to add friction to the slope. This will help allow a weaker gravity to stop the player from pushing up the slope.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .