AABB Sweeping, algorithm to solve "stacking box" problem

Posted by Ivo Wetzel on Game Development See other posts from Game Development or by Ivo Wetzel
Published on 2012-06-30T14:43:42Z Indexed on 2012/06/30 15:25 UTC
Read the original article Hit count: 400

I'm currently working on a simple AABB collision system and after some fiddling the sweeping of a single box vs. another and the calculation of the response velocity needed to push them apart works flawlessly.

Now on to the new problem, imagine I'm having a stack of boxes which are falling towards a ground box which isn't moving:

enter image description here

Each of these boxes has a vertical velocity for the "gravity" value, let's say this velocity is 5.

Now, the result is that they all fall into each other:

enter image description here

The reason is obvious, since all the boxes have a downward velocity of 5, this results in no collisions when calculating the relative velocity between the boxes during sweeping.

Note: The red ground box here is static (always 0 velocity, can utilize spatial partitioning ), and all dynamic > static collisions are resolved first, thus the fact that the boxes stop correctly at this ground box.

So, this seems to be simply an issue with the order the boxes are sweept against each other.

I imagine that sorting the boxes based on their x and y velocities and then sweeping these groups correctly against each other may resolve this issues.

So, I'm looking for algorithms / examples on how to implement such a system.

The code can be found here: https://github.com/BonsaiDen/aabb

The two files which are of interest are [box/Dynamic.lua][3] and [box/Manager.lua][4].

The project is using Love2D in case you want to run it.

© Game Development or respective owner

Related posts about collision-detection

Related posts about algorithm