I am trying to make a character(1) follow another character(2) and when character(1) gets close enough to stop moving. The problem is , is that it only works some times. Does anyone have any idea how to change it so it works.
//follow the character with movment
onClipEvent (enterFrame) {
if (this._x<_root.player._x && _root.player._x-this._x<100 or this._x>_root.player._x && this._x-_root.player._x<100) {
_root.sven.sven_body.sven_body_sword.sve nviking_sword_walking.gotoAndPlay("stop"
);
_root.sven.sven_legs.gotoAndPlay("stop")
;
} else {
if (this._x<_root.player._x && _root.player._x-this._x>=300 or this._x>_root.player._x && this._x-_root.player._x>=300) {
_root.sven.sven_body.sven_body_sword.sve nviking_sword_walking.gotoAndPlay("walk"
);
_root.sven.sven_legs.gotoAndPlay("walk")
;
}
// follow the character within boundaries
if (this._x>=1200) {
this = 0;
}
if (this._x<_root.player._x && _root.player._x-this._x<300) {
this._x += 3;
this.dir = 1;
// follow the character within boundaries part2
} else {
if (this._x<=-2150) {
this = 0;
}
if (this._x>_root.player._x && this._x-_root.player._x<300) {
this._x -= 3;
this.dir = -1;
}
}
}
}