Sign in to follow this  
jrh2365

Sliding AABB collision - getting stuck on edges

Recommended Posts

I'm working on a 3D tile based game and I'm using AABB collision detection. For every cube that the player is intersecting, I find the axis along which the player is intersecting the cube the least, and push the player out of the cube along that axis.

Depending on the order that the cubes are checked in, this can cause problems when sliding along the edge of multiple cubes. I have created a diagram that should explain the problem:

http://imgur.com/mmK0W.png

Arrow #1 is the attempted movement of the player. The other arrows are the collision response.
In the left diagram, collision is tested against the right cube first, causing the player to be pushed to the left, and then upwards. (bad)
In the right diagram, collision is tested against the left cube first, causing the player to be pushed upwards, at which point the player is no longer intersecting the other cube. (good)
Any ideas on what the most efficient way to solve this might be? Or any better ways to handle the collision response?

Thank you.

Share this post


Link to post
Share on other sites
It might be better to simply reverse the player's motion in some way (for instance, binary search) until the player no longer intersects any cube, then find some way to resolve the remaining part of the motion in the correct direction (eg find the nearest cube edge to the player, and direct the remaining movement along that line). You'd then feed the resolved movement back through the collision function to deal with any new collisions that arise from the updated movement, and repeat until the entire time-step has been processed.

Share this post


Link to post
Share on other sites
What you could do is:

Assume this is 2d for a moment.
Calculate how much you want the players block to move ( call it dx,dy)
Move the player block along its x axis (dx)
Check for collisions and push player block back along the x axis if colliding
Move player block along its y axis (dy)
Check for collisions and push player block back along the y axis if colliding

I used this very same system for this game:
http://dandanger.blogspot.com/2009/04/keith-goes-painting-is-bouncey-squishy.html

... and it worked fine for most cases ^_^

Share this post


Link to post
Share on other sites
Thanks for the input so far, guys.

@shaolinspin
I will have to think about how I would implement that.

@Dan Danger
I can't help but think that I tried to use this before in 3D and ran into issues. Could you share any of the cases for which it did not work fine? It's also possible that adding a 3rd dimension introduces some problems. I'll probably give it a shot though, thanks.


Thank you, and more ideas are still welcome :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this