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 and box/Manager.lua.

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

  • \$\begingroup\$ why don't you resolve static collisions first? and then you need to decrease your time steps. \$\endgroup\$
    – Ali1S232
    Jun 30, 2012 at 16:03
  • \$\begingroup\$ Sorting from lowest to highest is important to get good stacked box behavior in traditional discrete collision/physics systems. Unsure about swept volumes \$\endgroup\$ Jun 30, 2012 at 19:06
  • \$\begingroup\$ @Gajet I'm already doing the static ones first (that's why they don't fall through the red box which is the ground in this case) but the white boxes need to stack on top of each other. \$\endgroup\$
    – Ivo Wetzel
    Jun 30, 2012 at 19:46
  • \$\begingroup\$ @seanmiddleditch That might work out as a quick fix, now the question is how to make it work in cases where the gravity is inverted. \$\endgroup\$
    – Ivo Wetzel
    Jun 30, 2012 at 19:47
  • 1
    \$\begingroup\$ @Ivo Wetzel again in discrete systems, that effect is resolved by running multiple iterations of the contact resolver every physics update. It does not eliminate the innacuracies, but greatly reduces them. A great great number of tweaks and special hacks are required to get good stacking behavior. The only way to do it perfectly would be to use elastic bodies (no real objects are perfectly inelastic), infinitely small time steps, and resolve all collisions simultaneously. :) \$\endgroup\$ Jul 2, 2012 at 1:03

1 Answer 1


I'm not sure if this is how other systems solve this problem but here is an idea:

  1. first move all objects like you normally do.
  2. resolve all static vs dynamic collisions.
  3. resolve all dynamic vs dynamic collision.
  4. for every dynamic object which had a collision resolve all collision.
  5. repeat step 4 until either there is no collisions left or you reach a limit of some kind (for example you reach more than 10 iterations)

also as I previously mentioned reducing time step will surly help fixing that bug.

  • \$\begingroup\$ +1, this is pretty much the only reliable way to allow collisions to propagate across a chain of multiple objects in one time step. It occurs to me that simulating a Newton's cradle could make a good test case. \$\endgroup\$ Aug 31, 2012 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .