In the game that I am making I want to make it so that the zombies can't walk through each other or the player.

I don't want to make it so that the zombies stop for a while or move in another direction when they hit each other because it looks weird and I want the zombies to follow the player always. What I was thinking was to keep track of the zombies x and y position before (which I'm already doing) and then when it collides with another zombie or the player it will teleport to the last x and y position before it collided with another sprite. 

Would this work? Is there a better way to do it on? And how would I keep track of the latest x and y position before the zombie collided with another sprite? 

I already have the code that hecks the collision for the zombies

```
for(int i = 0; i < zombies.size(); i++){
            Zombie z = (Zombie) zombies.get(i);
            Rectangle r2 = z.getBounds();
            for(int j = i + 1; j < zombies.size(); j++){
                Zombie z2 = (Zombie) zombies.get(j);
                Rectangle r1 = z2.getBounds();
                if(r2.intersects(r1)){
                    //the code for stoping the sprites from going through each other should be here
                }
            }
        }

```

I am just wondering what I should have in the if statement to make the sprites not going through each other.