   platformer getting player to stick on ground
  Hello, I am using box2d in a platform game and it is very good however, when the player reaches the end of a platform and there is an inclined ramp like a stairs next to the platform the player will fly forward in the air a little before hitting the incline plane.Here is an example in ascii art: . ____________  / //The dot is where the player would be when running to the left fast on this land.What is a good technique to get the player to "stick" to the ground so that he does not go into the air shortly because of his momentum?Also, when applying linear velocity in the X direction vector only, the player will climb up inclined plane stairs slower than running on straight ground.  What is a good technique to adjust the linear velocity vector to match the incline plane so that the player travels the same speed on incline planes as on completely horizontal planes, without the player then shooting off the incline like a skateboard ramp?   
  To stick to the ground, you want to apply increased gravity to the player while they're on the ground. Then you need to recognize when they stop being grounded and revert to normal gravity. You may need to manually "back up" the player's position when they run off of cliffs so the increased gravity isn't visible. To run up ramps at speed, you need to convert the retarding portion of the collision vector into an upwards portion. For example, if the player is traveling to the right and runs into a 45° slope, their collision vector would be <-.707, -.707>, that is, left and upwards. You want to convert that into <0, -1.414> so the player continues to go horizontally at the same speed.   ;  do a trace from the centre of the player towards the ground, to find where the ground is from his feet. If it is too far away, then the player is on a slope that is too steep and will start a free fall.   ;  It also helps to have additional art for the character with feet positioned in a natural way for walking up the slope. Unless your "character" is a ball or something. :)   ;Quote:Original post by DerakonTo stick to the ground, you want to apply increased gravity to the player while they're on the ground. Then you need to recognize when they stop being grounded and revert to normal gravity. You may need to manually "back up" the player's position when they run off of cliffs so the increased gravity isn't visible. To run up ramps at speed, you need to convert the retarding portion of the collision vector into an upwards portion. For example, if the player is traveling to the right and runs into a 45° slope, their collision vector would be <-.707, -.707>, that is, left and upwards. You want to convert that into <0, -1.414> so the player continues to go horizontally at the same speed.Applying a downward velocity on the player while it is on the ground is not a good solution at all.  I tried just now and it is hard to move and when it does reach a slope it shoots right down it, without eliminating the problem.I am already modifying the linear velocity to match whatever normal the player is touching the ground with.  This is necessary, but when the player goes from a horizontal floor to climbing up onto a slope, there is a small stoppage point where they meet where the velocity adjusts only after the tick (because you cannot change the velocity of a body in the ContactListener). Caching the contact points creates the problem of figuring out where the point corresponded in respect to the collision box of the player while the players position is now updated.   ;Quote:Original post by johnson56kApplying a downward velocity on the player while it is on the ground is not a good solution at all.  I tried just now and it is hard to move and when it does reach a slope it shoots right down it, without eliminating the problem.I am already modifying the linear velocity to match whatever normal the player is touching the ground with.  This is necessary, but when the player goes from a horizontal floor to climbing up onto a slope, there is a small stoppage point where they meet where the velocity adjusts only after the tick (because you cannot change the velocity of a body in the ContactListener). Caching the contact points creates the problem of figuring out where the point corresponded in respect to the collision box of the player while the players position is now updated.The solution I described is the one I'm using in my own game, which in turn was cribbed from a description of Super Metroid's physics (Super Metroid being a commercial game that has a ground-following protagonist). The basic concept is sound; however, you can't expect to simply plop it into your code and have things Just Work. Physics tends to require a lot of tweaking.From your statement "it is hard to move", it sounds like you have some sort of gravity-proportional friction or maximum total velocity being imposed on the player, which is limiting his running speed. If the latter, I'd suggest separate maximum horizontal and vertical velocities. If the former, track it down and remove it. :) As for sliding down slopes, that one took me a bit to fix too. This is where changing the collision vector comes in -- whenever the player encounters a slope, their collision vector should be entirely vertical. That prevents sliding down slopes even as it allows players to run up slopes at full speed.I'm afraid I don't understand your second paragraph. It might help to have a description of your overall design and what ContactListeners are. Remember, though, that you shouldn't be changing the player's velocity; rather, you need to change their position, via the collision vector. The player's running velocity should always be horizontal with a strong "ground-seeking gravity" pull downwards. That way they'll keep bumping into the ground so they can follow it.   ;Quote:Original post by DerakonThe solution I described is the one I'm using in my own game, which in turn was cribbed from a description of Super Metroid's physics (Super Metroid being a commercial game that has a ground-following protagonist). The basic concept is sound; however, you can't expect to simply plop it into your code and have things Just Work. Physics tends to require a lot of tweaking.From your statement "it is hard to move", it sounds like you have some sort of gravity-proportional friction or maximum total velocity being imposed on the player, which is limiting his running speed. If the latter, I'd suggest separate maximum horizontal and vertical velocities. If the former, track it down and remove it. :) As for sliding down slopes, that one took me a bit to fix too. This is where changing the collision vector comes in -- whenever the player encounters a slope, their collision vector should be entirely vertical. That prevents sliding down slopes even as it allows players to run up slopes at full speed.I'm afraid I don't understand your second paragraph. It might help to have a description of your overall design and what ContactListeners are. Remember, though, that you shouldn't be changing the player's velocity; rather, you need to change their position, via the collision vector. The player's running velocity should always be horizontal with a strong "ground-seeking gravity" pull downwards. That way they'll keep bumping into the ground so they can follow it.i am using box2d and you are unable to change vectors or positions or anything when something encounters a slope because you can't change any of the physics properties inside of the ContactListener callback.  Even if you try to cache the position of bodies inside of the callback they will not be where they would be at the point of contact but where they are at the end of the physics step.  This means that if you have a ground seeking gravity during one tick it will not be updated until the next tick and at that point the body has already snapped down the slope.About the only solution I can think of is moving the body manually and calling box2d functions to test if the body is colliding with anything and adjusting the position, but for some reason the floating point values of these functions are not accurate so the body will be set inside of another body and then bounced out the next tick, which is really annoying.   