0
votes

I have created a Box2D based map for my platformer using ChainShape which has different angle slopes (no more than 45°). My problem is the slope collision with my player. The player' body has 2 fixtures, a rectangle and a circle below it. Whenever I move the player (the method doesn't matter the results are the same) and I stop on the middle of a slope I slowly glide down. I managed to temporarily fix that but the main reason for this post is the fact that whenever I leave a slope l I shoot out because I still have some impulse left from the previous movement. Same thing happens when I enter a downwards slope, or when I stop on a slope and I start moving again.

Entering / leaving the slope:

(The red lines are the desired movement, the black is the movement I have right now)

Start moving on a slope:

(The red lines are the desired movement, the black is the movement I have right now)

Could you please help me out with this problem? I don't mind if your answer is detailed either.

1
What is the friction on the bodies? Can you post an MCVE that we can play with? - Kevin Workman
Sorry I can't post it I barely have any time. The body's shape is shown on the linked pictures, it has the basic properties only higher mass wich I changed manually. Let me reprhase the question. How would you achieve the desired movement shown on the linked pictures in my original post. I'm trying to make an old-school movement platformer. Maybe the Rogue Legacy movement system is a good example of what I'd like to do. Please keep in mind that I'm planning on useing different angle slopes. - user3819849

1 Answers

0
votes

I've found the easiest way to stop the character sliding on a slope is to set the bodies linear dampening to Infinity when they player releases the move button and the body is grounded, which I'm using ray tracing to test for.

As for your issues with the character not following the slopes, this is simply due to momentum. When you reach the top of the slope, your body still has a some upward momentum which it has to clear. Same as when you're approaching a downward slope - your body still has some horizontal momentum to clear. I've had some success with ray tracing to find the normal of the slope below the player's position, and manually setting the body's velocity to match the tangent, however this not be applicable in your application.

As for your second issue, with starting movement on a slope, I expect you are applying a direct horizontal impulse, which is throwing the body off the slope. Again this could be rectified by finding the gradient of the slope where the player is standing, and applying the force at the appropriate angle.