1
\$\begingroup\$

Sorry for my bad english.

In my game, to resolve collision of a moving-box (e.g. the player) and fixed-boxes (e.g. tiles) :-

I check in advance whether a moving-box is going to collide with a fixed-box. If yes, then start moving the moving-box in 1 unit displacement in the direction of original displacement but only after checking in advance whether the next movement will result in a horizontal or vertical collision with any fixed-box. If in the next move it is going to collide with a fixed-box horizontally, then the x side of the moving-box is resolved and no more displacement in horizontal direction. Same for the y side.

But my problem is - how to resolve the collision of two (or more) moving axis-aligned non-rotating boxes?

What other people do is update position (resolving collision in the process) of the moving-boxes individually (one box at a time). That is wrong because in a certain time all of the moving-boxes are supposed to move simultaneously. So, this would result in wrong collision resolution. People won't notice it but collision would be resolved in wrong direction.

Other people separate the boxes using a minimum translation vector which they calculate using Separating Axis Theorem. This would also result in wrong resolution since the axis might not be the one that the boxes were supposed to be in contact with before intersecting with each other.

How can I resolve collision of two moving axis-aligned non-rotating 2d boxes correctly ?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.