# Trigonometry localToGlobal problem?

**URL:** <https://forum.kirupa.com/t/trigonometry-localtoglobal-problem/302918>\
**Category:** Uncategorized\
**Created:** [January 10, 2010, 3:46am UTC](https://forum.kirupa.com/t/trigonometry-localtoglobal-problem/302918 "2010-01-10T03:46:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beano](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@beano](https://forum.kirupa.com/u/beano)\
**Post date:** [January 10, 2010, 3:46am UTC](https://forum.kirupa.com/t/trigonometry-localtoglobal-problem/302918/1 "2010-01-10T03:46:58Z")

</div>

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

```auto

//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
