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?


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.

  • \$\begingroup\$ 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. \$\endgroup\$ – AJM Oct 29 '11 at 12:15
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – yaustar Oct 29 '11 at 12:24
  • \$\begingroup\$ @yaustar Actually Mario has no collision with enemies at all. It just takes damage when its hitbox overlaps them. \$\endgroup\$ – Winter May 23 '17 at 23:45

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.


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.

  • \$\begingroup\$ That's extremly unstable. The FPS in your game could spike up anytime the player makes a mess by pushing light object. It would be better to resolve it next frame. \$\endgroup\$ – Winter May 24 '17 at 12:37

Your Answer

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

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