【发布时间】:2018-09-17 21:50:52
【问题描述】:
我想做一个简单的飞行器控制器,统一起来看起来不太现实。我看了一些飞机物理学的视频。并统一制作一个简单的脚本,但是如果我开始,我的飞机无法移动,或者如果我将阻力更改为零,它就无法升起。我尝试使用真实数据并从 wiki(F22 Raptor) 获取。对于我的游戏对象,我给了刚体组件质量 = 19670 kg。 发动机推力 = 2 * 116000.0f 牛顿。
private void calculateEnginePower()
{
EnginePower = engineThrust * ThrottleInput;
}
private void calculateForces()
{
angleOfAttack = Vector3.Angle(Vector3.forward, rb.velocity);
angleOfAttack = Mathf.Clamp(angleOfAttack, 0, 90);
coefficient = Mathf.Pow(1225.04f * rb.velocity.magnitude, 2) - 1; //M^2-2 where: M is mach.
if (coefficient > 0.0f)
coefficientLift = (4 * angleOfAttack) / Mathf.Sqrt(coefficient);
lift = 1.2754f * 0.5f * Mathf.Pow(rb.velocity.magnitude, 2) * coefficientLift * 78.04f; // densy1.2754 kg/m3, speed m/s , (F22)Wing area: 840 ft² (78.04 m²)
coefficientDrag = 0.021f;
rb.drag = coefficientDrag * 0.5f * Mathf.Pow(rb.velocity.magnitude,2) * 1.2754f * 78.04f;
rb.AddForce(transform.up * lift);
rb.AddForce(transform.forward * EnginePower);
}
使用了这些公式:
对于升力: Lift formula 对于升力系数: Cl formula 对于拖动: Drag formula 对于阻力系数:我也使用了来自 wiki 的数据(0.021f)。
【问题讨论】:
-
您是否尝试过调试以查看
lift和EnginePower的值?你在哪里打电话calculateForces? -
roll,pitch... 来自键盘和鼠标的输入,EnginePower 是一个简单的属性,我在 void Update 内的控制器中调用 Move 函数。 public void Move(float roll, float pitch, float yaw, float throttle) { // 将输入参数传入properties.s RollInput = roll;音高输入 = 音高;偏航输入 = 偏航;油门输入 = 油门;空气刹车 = 假;计算引擎功率();计算力();计算旋转(); }
-
你也可以在Move函数中调用它进行调试。 private void debugThings() { Debug.Log("Aoa: " + angleOfAttack); Debug.Log("cL:" + coefficientLift); Debug.Log("电梯:" +电梯); Debug.Log("cD:" + coefficientDrag); Debug.Log("拖动:" + 拖动); Debug.Log("质量:" + rb.mass); Debug.Log("速度:" + rb.velocity.magnitude); Debug.DrawLine(rb.position, rb.velocity * 300, Color.red); }
-
lift的典型值是什么?它们与飞机的重量相比如何? (g在 Unity 单位中可能不是 9.81,但我不确定 - 最好的方法是通过实验找出答案)。根据this forum,drag属性似乎有相当随意的单位(目前还不清楚它确切代表什么)
标签: c# unity3d math air physics