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

This topic is 4112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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
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
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!

• 11
• 19
• 12
• 9
• 34
• ### Forum Statistics

• Total Topics
631398
• Total Posts
2999840
×