# How do I avoid causing more collisions, when resolving multiple AABB collisions?

I have a lot of AABB bouncing on the screen. Doing collision/response between 2 AABB is fairly easy, but how do you handle this when you can be pulling AABB's apart but making them getting into another AABB? I mean something like this scenario:

1. We have 3 AABBs.

2. We check if first one collides with the other two. No collision is found.

3. We check if second collides agains the third (we don't need to recheck agains first). We find a collision, we separate second AABB form third but it intersects now with first one.

This will produce a bad response/collision detection. How do you handle this chained collisions?

Edit: I forgot to say that all aabb are dynamics objects. I mean, they move.

-

## 1 Answer

Most physics engines that I have seen/used solves this problem by apply a force to the objects instead of directly changing the positions. This does it so that we only need to check collisions once between each object(or not even that if one is using culling algorithms) per update.

e.g. if you only have circles you simply give colliding objects a force away from the centre that is scaled to how close the other object is. AABBs is also somewhat simple as long as you don't need to rotate them. When I implemented a simple physics system(although we used OBBs but we still didn't care about angular velocity) we pushed the objects in the direction of its the closest edge.

-
But wouldn't the problem I stated still exist? Or are you expecting that applying this forces over time bodies will be fully separated?. – Notbad Jan 31 '12 at 18:38
Yes they should separate very quickly as long as you scale the forces properly(just try out some numbers and you will and be fine). Remember that both of the objects in a collision push on eachother... – Cpt. Red Jan 31 '12 at 23:11
Seems I have to try this, and it could work. Thanks. – Notbad Feb 1 '12 at 8:05
@Notbad Do accept his answer if this helped you. – Arcane Engineer Feb 1 '12 at 13:57
Sorry, I forgot to accept it. It is done now. – Notbad Feb 1 '12 at 22:08