我正在构建一个基于太空船的游戏,但我遇到了一个间歇性问题,我的 Force 的天空火箭飞到了无限远。我假设问题与这些关系船有关:
- 加速度取决于力
- 速度取决于加速度
- DragForce(力)取决于速度
这是船游戏: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;