【发布时间】:2012-02-22 07:44:29
【问题描述】:
当玩家扫射时,我有代表玩家船逐渐倾斜的模型。例如,这是使船向右倾斜的代码:
在 Game 类的 Update() 中:
if (ship.rightTurnProgress < 1 && (currentKeyState.IsKeyDown(Keys.D)))
{
ship.rightTurnProgress += (float)gameTime.ElapsedGameTime.TotalSeconds * 30;
}
在 Ship 类的 Update() 中:
if (currentKeyState.IsKeyDown(Keys.D))
{
Velocity += Vector3.Right * VelocityScale * 10.0f;
RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) *
Matrix.CreateRotationY(0.4f * rightTurnProgress);
}
这就是我正在尝试做的事情,以使它在停止扫射时轻松摆脱精益:
在 Game 类的 Update() 中:
if (ship.rightTurnProgress > 0 && currentKeyState.IsKeyUp(Keys.D))
{
ship.rightTurnProgress -= (float)gameTime.ElapsedGameTime.TotalSeconds * 30;
}
在 Ship 类的 Update() 中:
if (currentKeyState.IsKeyUp(Keys.D) && rightTurnProgress > 0)
{
RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) *
Matrix.CreateRotationY(-0.4f * rightTurnProgress);
}
既然放宽到精益工作没有问题,我认为放宽精益将是一个简单的逆转过程的问题。但是,经过长时间的扫射后,它往往不会一直回到默认位置。如果您点击该键,它会一直弹回到-相反方向的完全倾斜状态。这根本不是我所期望的。我在这里错过了什么?
【问题讨论】: