Sign in to follow this  
Pracka

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


Link to post
Share on other sites
Guest Anonymous Poster   
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   
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this