Simple sliding collisions

posted in Gamedev info
Published January 26, 2015
Advertisement
Simple sliding collisions

simple sliding collisions:

for AABBs:

1. start by calculating how much to move the player as usual:

dx = player.speed * sin(player.yr)
dz = player.speed * cos(player.yr)

2. apply dx and dz, and check for collsions as usual.

3. if a collison is indicated:

3a. apply JUST dx and check for collisions.

3b. apply JUST dz and check for collisions.

3c. if collision in dx but not dz, move the player by dz.

3d. if collision in dz but not dx, move the player by dx.

3e. if collisions in both dx and dz, don't move the player.

3f. if collisions occur in neither dx nor dz, don't move the player.

note that this may also work for types of collision checks other than simple AABB.


Note:

case 3e - collisions ahead, left, and right - is when the player is facing into some sort of corner (continuous or otherwise).

case 3f - collisions ahead, but not left or right - is when the player is facing a telephone pole or similar object.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement