# Why are they going through walls?(simple problem)

## Recommended Posts

Pracka    122
I've got little problem with my simple enemy colision. My simple enemy just move by change. It change direction in every 3 seconds. Problem is that sometimes I really can't you say when exectly it go through the wall, but I think that is especiall in cornes. I'm adding code which take care about collision: if(direction == UP) { positionY -= 0.2f; timer.run(); // this change direction of enemy }else if(direction == DOWN) { positionY += 0.2f; timer.run(); } else if(direction == RIGHT) { position -= 0.2f; timer.run(); } else if(direction == LEFT) { position += 0.2f; timer.run(); } You can look on screeshot to have better conception http://www.kpk.unas.cz/026.jpg

##### Share on other sites
Guest Anonymous Poster
remove the else like below :

if(direction == UP)
{
positionY -= 0.2f;
timer.run(); // this change direction of enemy
}

if(direction == DOWN) {
positionY += 0.2f;
timer.run();
}

if(direction == RIGHT) {
position -= 0.2f;
timer.run();
}

if(direction == LEFT) {
position += 0.2f;
timer.run();
}

it should work fine with this code

##### Share on other sites
Guest Anonymous Poster
The Previous code is wrong - My bad - you should use the following code:

if(direction == UP)
{
positionY -= 0.2f;
timer.run(); // this change direction of enemy
} else if(direction == DOWN) {
positionY += 0.2f;
timer.run();
}

if(direction == RIGHT) {
position -= 0.2f;
timer.run();
} else if(direction == LEFT) {
position += 0.2f;
timer.run();
}

the problem was the corners because you changed only one direction and not both!