Hello,
The code below is supposed to make this class follow the player but instead it makes the enemy get near the player and then stop and jerk, I know what the jerking is caused by but I do not know why it will not actually follow and eventually touch the player. When I unleash multiple instances of the class on the player they will literally make a circle around it and jerk.
I believe it is a coordinate problem with localToGlobal or something like that, however that does not make sense because the player and the follower both have parents of Stage. So I figure it is my trigonometry, but I have checked it and I think it is right. So can anybody spot anything wrong in my code?
if you would like
//find the x and y distances between this class and the player
var distanceX:Number = player.x-this.x;
var distanceY:Number = player.y-this.y;
//find the rotation to face the player in radians
var radians:Number = Math.atan2(distanceY,distanceX);
//convert the rotation to degrees and apply it
var degrees:Number = radians*180/Math.PI;
this.rotation = degrees;
//find the trig ratio for the x and y movement
var xRatio:Number = Math.cos(degrees);
var yRatio:Number = Math.sin(degrees);
//apply the ratio and multiply it by the constant speed
this.x += xRatio*SPEED;
this.y += yRatio*SPEED;
thanks,
beano