Sign in to follow this  

Tile based collision resolution

Recommended Posts

BradDaBug    913
I've got a 2D pathing map which represents each tile as either blocking or nonblocking. A blocking tile means nothing can move onto it. Stuff moving around is represented as a circle with some radius. What I want to do is detect collisions with these circles and the tiles. This part is fairly straight forward. The process is just that I find the distance from the center of the circle to the tile, and compare that to the radius of the circle + radius of the tile. That means that the square tiles will be considered circles, but that's good enough. So let's say an object wants to move into a wall. The final position of the object is tested for collisions, and some are detected. I want to be able to find some vector to move the final position of the object and create a final final position. What I'm doing so far is finding the depth and direction of each collision (each tile has at most 1 collision with each circle). If I add up all these collision vectors I end up with a vector pointing in the direction that I need to translate the final position, I think. But while the direction of this vector might be handy, the length of the vector isn't. I can't figure out how to find the length that I need to move. Could I just take the largest collision vector and use that magnitude? Am I on the right track? Am I completely wrong?

Share this post

Link to post
Share on other sites
jyk    2094
Original post by BradDaBug
Well, at first glance the method you proposed doesn't seem like it would always work (although I admit I didn't think that hard about it). Another way to go would be to process collisions sequentially. Find all the intersections for the target position, and resolve the one with the deepest penetration. Rinse and repeat until no collisions are detected, bailing back to the start position after some maximum number of iterations if necessary.

I'll also mention that it's quite easy to find the closest point on a box (square or rectangle in 2d) to a point, so there's no reason to approximate your tiles with circles unless that's really what you prefer.

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