Circular movement - eliminating speed ups near Y = 0
- by Fibericon
I have a basic algorithm to rotate an enemy around a 200 unit radius circle with center 0. This is how I'm achieving that:
if (position.Y <= 0 && position.X > -200)
{
position.X -= 2;
position.Y = 0 - (float)Math.Sqrt((200 * 200) - (position.X * position.X));
}
else
{
position.X += 2;
position.Y = (float)Math.Sqrt((200 * 200) - (position.X * position.X));
}
It does work, and I've ensured that at no point does either X or Y equal NaN. However, when Y approaches 0, it seems to go significantly faster. This surprises me, because the Y values are locked to the X, which is being incremented by a steady amount. What can I do to smooth the speed?