asked on
position += new Vector2((float)Math.Sin(CurrentAngle) * Velocity * Elapsed, (float)Math.Cos(CurrentAngle) * Velocity * Elapsed);
float TargetAngle = (float)(Math.PI) - (float)Math.Atan2(target.Y - position.Y, target.X - position.X);
if (target.X == position.X)
{
TargetAngle = (float)(Math.PI * 0.75f);
}
if (target.Y == position.Y)
{
TargetAngle = 0;
}
float angleDelta = Math.Abs(CurrentAngle - TargetAngle);
if (angleDelta >= RotationSpeed * Elapsed)
{
// We need to cap to RotationSpeed
if (AngleDirection(CurrentAngle,TargetAngle))
{
CurrentAngle += RotationSpeed * Elapsed;
}
else
{
CurrentAngle -= RotationSpeed * Elapsed;
}
}
else
{
// We can rotate without limitation!
CurrentAngle = TargetAngle;
}