# AS3 trig

**URL:** <https://forum.kirupa.com/t/as3-trig/323974>\
**Category:** flash\
**Created:** [July 26, 2011, 4:30pm UTC](https://forum.kirupa.com/t/as3-trig/323974 "2011-07-26T16:30:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blargh](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Blargh](https://forum.kirupa.com/u/Blargh)\
**Post date:** [July 26, 2011, 4:30pm UTC](https://forum.kirupa.com/t/as3-trig/323974/1 "2011-07-26T16:30:39Z")

</div>

So I have two points, one of them is the player controlled point, a ship, and the other is an enemy. I want the enemy to follow the ship. So far, my code says:

```auto
                  xDest = ourShip.x - x; yDest = ourShip.y - y; angle = Math.atan2(yDest,xDest); Math.round( angle * 100 ) / 100; rotation = angle / (Math.PI / 180); x = (radius * Math.cos(angle) + startingX); y = (radius * Math.sin(angle) + startingY); radius += speed;

```

Now, this works fine, until the enemy gets close to the ship and then the enemy starts to go crazy and jumps around the screen. For the life of me I can’t figure out why it works fine at a distance but breaks down when they get close. Can anyone help me out?  
Thanks
