I want a Missile to follow a player with following rules:
- when the player is at the right side relative to the missile, change the rotation to the right at a fixed rate
- else change the rotation to the left at the same rate
if (missile.Rotation > 0 && missile.Rotation < Math.PI)
{
if (angle > missile.Rotation && angle < missile.Rotation + Math.PI)
{
missile.Rotation += 0.05f;
}
else
{
missile.Rotation -= 0.05f;
}
}
else
{
if (angle < missile.Rotation && angle > missile.Rotation - Math.PI)
{
missile.Rotation -= 0.05f;
}
else
{
missile.Rotation += 0.05f;
}
}
missile.Position += new Vector2((float)(5 * gameTime.ElapsedGameTime.TotalSeconds * Math.Cos(missile.Rotation)), (float)(5 * gameTime.ElapsedGameTime.TotalSeconds * Math.Sin(missile.Rotation)));
With this code, some missiles seem to bug, when I jump with the player, the missiles go into a endless loop which cannot be stopped (they fly in a circle)
the coordinate system is like in XNA (360/0° is at the right, 270° is top...)
anyone can help me?