Jump to content
  • Advertisement
Sign in to follow this  
Pracka

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!