I don't know if the solution to this problem is quite straight-foward but I really don't know how to handle collision resolution on a game where the player walks on an ascendent floor which is not flat. How can the player position itself on the y axis depend on the ground x and z (opengl coords)? What if the floor's slope is too much and the player can't go up, how do you handle that?

I don't need any code, just a simple explanation would be great.


1 Answer 1


There are a few ways to tackle this problem. Once he has hit the slope, you could

  1. Change the direction he moves from only in the x-z plane to the cross product of the face's normal and the player's "strafe right" vector, (yielding a vector parallel to the face).
  2. When resolving collisions, move the player along the slope's normal to get him out of the ground. Every frame, he will move straight forward into the slope, then the collision will push him up and back out of the ground, so he will ascend.
  3. Change the direction he moves from his current "forward" vector to his forward vector projected onto the plane of the slope. This is similar to option 1.

To determine if the slope is too steep, you can

  1. Take the dot product of the slope's normal and the player's standard "forward" vector (both normalized), and ensure it is not less than some threshold (around -0.6 is probably getting too steep, -1 would be walking straight into a wall).
  2. Take the dot product of the standard "forward" vector and the new vector the player would take instead, if using option 1 or 3 from before. Ensure that this dot product is less than some threshold (1 is walking straight forward along a flat surface, 0.5 would be walking up a moderate slope, and 0 would be walking straight into a wall).
  • \$\begingroup\$ How about if the plane slope is too much like this __/ The normal would get him back where he came from if we apply the 2nd method. \$\endgroup\$
    – marcg11
    Commented Nov 26, 2012 at 15:17
  • \$\begingroup\$ Is that not what you want to occur? The 2nd method will only put him back where he started if the slope is completely vertical, unless gravity is also pulling him back down. Does your player slide downards from gravity? Is that intentional? \$\endgroup\$
    – Eric B
    Commented Nov 26, 2012 at 15:26
  • \$\begingroup\$ Well I just want know the all the possibilities. But yeah, I understand now. \$\endgroup\$
    – marcg11
    Commented Nov 26, 2012 at 15:30

You must log in to answer this question.

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