I have a method for orbiting a sprite (fleet) around another sprite (planet). The problem is that, over time, the fleet moves further away (very slowly, almost unnoticeable unless you let the orbit run for a few minutes).
public void Orbit()
{
// Planet's position - fleet position
Vector2 distanceToDestination = currentLocation.Position - position;
// Calculate fleet's rotation ( - right angle so fleet rotates clockwise)
rotation = MathHelper.WrapAngle((float)Math.Atan2(distanceToDestination.Y, distanceToDestination.X)) - Helpers.RightAngle;
// Get the direction that the fleet is facing
direction = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
// Fleet position, thrust is set to 0.4f
position = Vector2.Add(position, direction * thrust);
// Fleet rectangle
rect = new Rectangle((int)position.X, (int)position.Y, fleetTexture.Width, fleetTexture.Height);
}
public static class Helpers
{
public const float RightAngle = (float)Math.PI / 2;
}
I would be grateful if the community could point out why my fleet is not maintaining a consistent orbit, which is what I want to achieve! Many thanks in advance.