views:

106

answers:

2

I'm trying to figure out how to handle collisions with a player trying to move over sloped terrain. For example, consider if a player is at the bottom of a half-pipe and wants to go left:

  • At first the player is on the flat and can go directly left
  • At some point the player starts going up a slope, and so needs to go up and left in order to remain on top of the terrain

How should I handle this?

  • Should try and move the player directly left and see if they have collided with terrain - if they have then work out if I should nudge the players position?
  • Should I try and work out what the terrain to the players left looks like, and determine in advance what height the player should be placed at?
+3  A: 

You're going to need to check for collisions first regardless if your player can ever be in "free fall" - i.e. not constantly in contact with a surface. (It stands to reason - if you're not constantly in contact with a surface, then you won't know which "terrain" to try to get the "look" of.)

In general, I'd say try to move straight first, check for collision, and then if you find a collision, look at the normal to the surface you collided with and use that as a "nudge" force.

Amber
+1 for normal to surface
BlueRaja - Danny Pflughoeft
A: 

I'd suggest having a limit on the vertical change in the terrain that allows a character to "step up" it. e.g. anything up to 4 pixels. Then anything above this would require a "jump".

ck