我的太空船速度在下降
本文关键字:速度 太空船 我的 | 更新日期: 2023-09-27 18:24:12
我正在为Windows Phone编写一款太空游戏,使用一些已经停产的XNA。我需要船的速度逐渐降低,直到用户没有按下驱动按钮时速度降到零。这听起来很简单,但Velocity是一个Vector2,我不知道如何做到这一点。
position += velocity;
speed = 0.04f;
switch (driveBtn.CurrentButtonState)
{
case ControlButton.ButtonState.Released:
//Need to slow down ship when drive is not being held.
break;
case ControlButton.ButtonState.Pressing:
velocity.X += (float)Math.Cos(rotation) * speed;
velocity.Y += (float)Math.Sin(rotation) * speed;
break;
}
尝试划分速度:
velocity /= 2f;
另一个选项可以为您提供更平滑、更可控的速率,您可以使用线性插值:
float rate = 0.5f;
velocity = Vector2.Lerp(velocity, Vector2.Zero, rate);