Ok so I found this code and I have been messing around with it a bit and I had a question. Basically im trying to get it so the enemy fallows the player mc.It works pretty good. but im not to sure why when _root.grounded == false; the enemy just starts walking in a straight line. Rather then just stopping. Can someone help me out?
Thanks
Matt V
onClipEvent (load) {
spd = 2;
}
onClipEvent (enterFrame) {
if (_root.grounded) {
Xdiff = _root.player._x-_x;
Ydiff = _root.player._y-_y;
radAngle = Math.atan2(Ydiff, Xdiff);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
}
if (_rotation>180) {
_y += (spd*Math.cos(Math.PI/180*_rotation));
_x -= (spd*Math.sin(Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos(Math.PI/180*_rotation));
_x += (spd*Math.sin(Math.PI/180*_rotation));
}
}