Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I use a simple discrete collision detection system where I move all objects then check for collisions. I want any colliding objects to be separated (of course) and assigned appropriate response velocities (bounce, slide, stop, etc.).

When I have a pair of colliding objects, how do I separate them without ending up with one or both of them colliding with other objects?

share|improve this question
up vote 6 down vote accepted

This is not an easy problem to solve in general. In a physics engine it would be handled by the contraint solver. There are many different types of constraint solvers, but one of the easiest to understand is a sequential impulse solver.

Erin Catto gave a nice explanation of a sequential impulse solver at several previous GDC's, they can be downloaded from the Box2D download page, see the GDC 2009 one for example.

share|improve this answer
I'm curious about this. Given how common the need is for collision detection and resolution I've assumed there's at least a simplistic resolution algorithm suitable for arcade and action games. – AJM Oct 29 '11 at 12:15
Not really. In the old days (SNES etc), they got round issues like this with game design changes or compromises. Eg. In Super Mario, when the player got hit, Mario would be invincible for a couple of seconds to bypass second collisions. In Double Dragon, collisions are ignored for the player until the animation for falling backwards has finished. – yaustar Oct 29 '11 at 12:24

The only way you can keep this from happening is to prevent penetration in the first place. Before you move an object you make sure it's a legal move. Note that this means you must move your objects one at a time to avoid the case of two objects moving into each other.

If no penetration occurs you don't have to reset any positions and thus you won't trigger any secondary penetrations.

share|improve this answer

What I usually do is the following:

When you separate objects and you end up with more collisions, you just iterate again, until a maximum amount of steps is reached or the objects penetrate less than a predefined threshold.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.