My game processes world collisions followed by entity collisions. The problem here is that entities can break through walls the next frame when world checks are run again as a result of the prior collision resolution. For example:

  1. Entity1 is up against a wall and pushing against it
  2. Entity2 runs into Entity1, collision detection resolves Entity1 inside the wall.
  3. World collisions push Entity1 onto the other side of the wall.

What happens is that Entity2 pushes Entity1 into the wall far enough that when the world collision detection attempts to find the shortest distance out of the wall, that position happens to be on the other side.

  • \$\begingroup\$ Multibody collisions (more than 2 bodies) are a big physics topic with no true computational way of solving it perfectly. If these Entities have momentum (mass and velocity) then you can try and apply the concept of conservation of momentum treating the wall as an Entity with infinite mass. \$\endgroup\$ – RobCurr Mar 4 '13 at 17:08

The place to fix it is in step 2.

If Entity2 runs into Entity1, Entity1 gets moved, but only if the resulting location is not a new collision. In that case you'll have to move Entity2 back to it's original position or some other custom solution (for example: try moving Entity1 to a different direction that doesn't cause a collision).

| improve this answer | |
  • \$\begingroup\$ That's not suitable for a video game and in most situation, Entity1 has no place to go. A good and intuitive solution would be to prevent Entity2 from moving as if he was walking into a wall. \$\endgroup\$ – Winter May 24 '17 at 12:41

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