我想制作一个简单的飞行控制器,让它在unity中看起来更加真实。我看了一些与飞机物理相关的视频,并且在unity中编写了一个简单的脚本,但是当我启动时,我的飞机无法移动,如果我将阻力设置为零,则无法升空。我尝试使用真实数据,并从wiki(F22猛禽)获取数据。对于我的游戏对象,我给予了刚体组件质量=19670千克。发动机推力= 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力公式: Lift formula Lift系数公式: Cl formula 阻力公式: Drag formula 阻力系数公式:我也使用了维基百科上的数据(0.021f)。
lift
和EnginePower
的值吗?你在哪里调用calculateForces
函数? - Ian H.计算引擎功率(); 计算力量(); 计算旋转();
} - BoyeszDebug.DrawLine(rb.position, rb.velocity * 300, Color.red);
} - Boyesz