繁体   English   中英

具有2D运动的罕见物理边缘情况

[英]Rare physics edge case with 2D movement

我正在建造一个基于太空船的游戏,我有一个间歇性的问题,我的部队的天空火箭无限。 我假设这个问题与这些关系船有关:

  • 加速取决于力量
  • 速度取决于加速度
  • DragForce(Force)取决于Velocity

这是船游戏: http//shootr.signalr.net

这里是运动背后物理方程式的重新分解(使其不那么大,将某些函数组合起来)。

double PercentOfSecond = (DateTime.UtcNow - LastUpdated).TotalMilliseconds / 1000;

// Mass = 50
_acceleration += Forces / Mass;

Position += Velocity * PercentOfSecond + _acceleration * PercentOfSecond * PercentOfSecond;
Velocity += _acceleration * PercentOfSecond;

_acceleration = new Vector2();
Forces = new Vector2();

// DRAG_COEFICCIENT = .2,  DRAG_AREA = 5
Vector2 direction = new Vector2(Rotation), // Calculates the normalized vector to represent the rotation
        dragForce = .5 * Velocity * Velocity.Abs() * DRAG_COEFFICIENT * DRAG_AREA * -1;

Forces += direction * ENGINE_POWER; // Engine power = 110000

LastUpdated = DateTime.UtcNow;

首先,您有一个不恰当的操作,只有在假设向量初始化为零向量时才会起作用。 例如:

_acceleration += Forces / Mass; // your code
_acceleration = Forces / Mass; // what it should be

你的力量也应该是:

Forces = direction * ENGINE_POWER + dragForce;

如果这对您的问题没有帮助,那么您在计算方向向量时遇到问题。 确保它已标准化。 你的dragForce方程看起来很好。 但是,请确保添加它而不是减去,因为已经将dragForce乘以-1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM