我花了8个小时试图找到解决方案。
所以这是我的问题。我的船正在旋转,就像它绕着某个东西旋转一样,就像一根绳子。当我离起始位置越来越远时,我开始转动更多更奇怪的怪物。就像我附在一个字符串上一样。
以下是轮换和移动的代码。
public void MoveShip(List<InputAction> InputActionList, GameTime gameTime)
{
float second = (float)gameTime.ElapsedGameTime.TotalSeconds;
float currentTurningSpeed = second * TurningSpeed;
float leftRightRotation = 0;
float upDownRotation = 0;
float linearLeftRightRotation = 0;
foreach(InputAction action in InputActionList)
{
switch(action)
{
case InputAction.Left:
leftRightRotation -= currentTurningSpeed;
break;
case InputAction.Right:
leftRightRotation += currentTurningSpeed;
break;
case InputAction.Up:
upDownRotation += currentTurningSpeed;
break;
case InputAction.Down:
upDownRotation -= currentTurningSpeed;
break;
case InputAction.IncreaseSpeed:
if (ShipSpeed < MaxShipSpeed)
ShipSpeed += Acceleration;
break;
case InputAction.DecreaseSpeed:
if (ShipSpeed > MinShipSpeed)
ShipSpeed -= Acceleration;
break;
case InputAction.LinearLeft:
linearLeftRightRotation += currentTurningSpeed;
break;
case InputAction.LinearRight:
linearLeftRightRotation -= currentTurningSpeed;
break;
case InputAction.Fire1:
WeaponSystem2D.RequestFire(ShipPosition, ShipRotation);
break;
}
}
Quaternion currentRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), leftRightRotation) *
Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRotation) *
Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), linearLeftRightRotation);
currentRotation.Normalize();
ShipRotation *= currentRotation;
ShipPosition *= Vector3.Transform(new Vector3(0, 0, 1), ShipRotation) * (ShipSpeed * second);
ShipWorld = Matrix.CreateFromQuaternion(ShipRotation) * Matrix.CreateTranslation(ShipPosition);
}
有什么问题?它为什么这样做?我希望船在角钱上旋转,因为它是空间。
编辑: - 模型不是问题。
编辑2:没关系,旋转实际上正在工作,这是我的天空盒坏了!
答案 0 :(得分:0)
这段代码实际上是完美的,我的天空盒看起来好像坏了。