This question already has an answer here:
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:
- Entity1 is up against a wall and pushing against it
- Entity2 runs into Entity1, collision detection resolves Entity1 inside the wall.
- 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.