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