Try something like this when calculating the direction you want your missile to head in:
Vector2 direction = Vector2.Lerp(mousePosition, missilePosition, 0.5f);
This will get a direction that is 50% towards the direction you want.
質問
I was in need of help about creating a homing missile that would go towards the target I was given information and was able to do so but I have been looking into MathHelper.Lerp, that I was directed to try and use on the post, and have not found a reliable way to rotate the direction of the missile.
protected override void Update(GameTime gameTime)
{
mouse = Mouse.GetState();
mousePosition = new Vector2(mouse.X, mouse.Y);
delta = (float)gameTime.ElapsedGameTime.TotalSeconds * Speed;
direction = mousePosition - missilePosition;
direction.Normalize();
missilePosition += direction * delta;
d.X = mouse.X - missilePosition.X;
d.Y = mouse.Y - missilePosition.Y;
distance = Math.Sqrt((d.X * d.X) + (d.Y * d.Y));
v.X += d.X * turning;
v.X += d.X * turning;
Velocity = Math.Sqrt((v.X * v.X) + (v.Y * v.Y));
How would I use lerp to rotate the direction so the missile turns slowly?
解決
Try something like this when calculating the direction you want your missile to head in:
Vector2 direction = Vector2.Lerp(mousePosition, missilePosition, 0.5f);
This will get a direction that is 50% towards the direction you want.