Ok I am making a RPG and for some reason this code isnt working, What is suppose to happen is the enemy chases the main character and it mostly works. But for some reason he wont go left. I really dont know why it isn working because I have done this before with no problems. There are no syntax errors.
Here is the code.
function search_kill() {
if(this.x>_root.man._x){
this._x -= speed;
this.gotoAndStop(4);
}else if(this._x<_root.man._x){
this._x += speed;
this.gotoAndStop(3);
}else if (_root.man._y<this._y) {
this.walk = true;
this.gotoAndStop(2);
this._y -= speed;
}else if (_root.man._y>this._y) {
this.walk = true;
this.gotoAndStop(1);
this._y += speed;
}
if (this.hitTest(_root.man) && this.attack == 1) {
this.walk = false;
this.guard.gotoAndStop(2);
this.speed = 0;
} else {
this.attack = random(2)+1;
this.guard.gotoAndStop(1);
this.speed = 8;
}
}
Also I would like to add something so he will avoid walking threw walls.