//run after enemy
if (abs(self.x-target.x) > 450) {
if (self.x-target.x > 0){
left(1,0);
left(1,0);
}
else if (self.x-target.x < 0){
right(1,0);
right(1,0);
}
}
The > I colored red must of course be a < for your code.
Try this code:
There might be something wrong the the brackets though (those things: ( ) ), so you might need to fix that if you're using this code.
if (abs(self.x-target.x) > 450) {
if (self.x-target.x > 0){
left(1,0);
left(1,0);
}
else if (self.x-target.x < 0){
right(1,0);
right(1,0);
}
}
The > I colored red must of course be a < for your code.
Try this code:
Code:
if (self.x-target.x)*((self.facing?1:0)*2-1) < 0 && (self.x-target.x)*((self.facing?1:0)*2-1) < 300){
if (self.x-target.x > 0){left();}
else {right();}
There might be something wrong the the brackets though (those things: ( ) ), so you might need to fix that if you're using this code.