我想做一个简单的飞机控制器,看起来有点逼真。我看了一些飞机物理的视频。然后做一个简单的脚本,但是如果我开始,我的平面不能移动,或者如果我把拖动改为零,它就不能升起。我尝试使用真实数据,并从维基(F22猛禽)获取。对于我的游戏对象,我给了刚体组件质量= 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,对于阻力系数:我也使用了维基的数据(0.021f)。
发布于 2018-04-09 15:34:26
所以你的代码有很多问题。我已经在下面概述了它们;
计算力
问题:
angleOfAttack = Vector3.Angle(Vector3.forward, rb.velocity);
world-space.中包含
Vector3.forward和rb.velocityAoA是机翼的局部弦线和飞机的velocity之间的角度。Vector3.Angle将返回一个无符号的角度。AoA必须在正和负两个方向上工作,否则不可能出现负俯仰和反向飞行。

解决方案:将
rb.velocity移动到局部空间,并用三角函数求解AoA。
// *flip sign(s) if necessary*
var localVelocity = transform.InverseTransformDirection(rb.velocity);
var angleOfAttack = Mathf.Atan2(-localVelocity.y, localVelocity.z);问题:
coefficient = Mathf.Pow(1225.04f * rb.velocity.magnitude, 2) - 1;
当M > 1时,
4α/sqrt(M^2−1)是一个超音波系数。当速度为0时,这个方程将简化为sqrt(-1),这是一个将产生NaN的虚数。马赫表示为M=V/C,其中V=velocity和C=the speed of sound。您的1225.04f常量必须是以km/h为单位的C,而不是所需的m/s。你也是在乘法,而不是像等式中给出的那样除以。解决方案:使用提升线理论简化您的方程。
var aspectRatio = (wingSpan * wingSpan) / wingArea;
var inducedLift = angleOfAttack * (aspectRatio / (aspectRatio + 2f)) * 2f * Mathf.PI;
var inducedDrag = (inducedLift * inducedLift) / (aspectRatio * Mathf.PI);

来源:
问题:
rb.drag = coefficientDrag * 0.5f * Pow(rb.velocity.mag,2) * 1.2754f * 78.04f;
由于我们是手动计算和应用拖动,因此不需要
rb.drag。解决方案:将
rb.drag属性设置为可能的最小值。
rb.drag = Mathf.Epsilon; // set in Awake问题:
rb.AddForce(transform.up * lift);
对于lift,
transform.up不正确。Lift行为perpendicular to velocity,而drag行为parallel.

解决方案:通过将归一化的
lift矢量与飞机的横向交叉来计算velocity方向,并与velocity__相反地应用drag。
// *flip sign(s) if necessary*
var dragDirection = -rb.velocity.normalized;
var liftDirection = Vector3.Cross(dragDirection, transform.right);
rb.AddForce(liftDirection * lift + dragDirection * drag);你的lift公式看起来没问题,所以把它们放在一起看起来就像这样;(未测试)
public float wingSpan = 13.56f;
public float wingArea = 78.04f;
private float aspectRatio;
private void Awake ()
{
rb.drag = Mathf.Epsilon;
aspectRatio = (wingSpan * wingSpan) / wingArea;
}
private void calculateForces ()
{
// *flip sign(s) if necessary*
var localVelocity = transform.InverseTransformDirection(rb.velocity);
var angleOfAttack = Mathf.Atan2(-localVelocity.y, localVelocity.z);
// α * 2 * PI * (AR / AR + 2)
var inducedLift = angleOfAttack * (aspectRatio / (aspectRatio + 2f)) * 2f * Mathf.PI;
// CL ^ 2 / (AR * PI)
var inducedDrag = (inducedLift * inducedLift) / (aspectRatio * Mathf.PI);
// V ^ 2 * R * 0.5 * A
var pressure = rb.velocity.sqrMagnitude * 1.2754f * 0.5f * wingArea;
var lift = inducedLift * pressure;
var drag = (0.021f + inducedDrag) * pressure;
// *flip sign(s) if necessary*
var dragDirection = rb.velocity.normalized;
var liftDirection = Vector3.Cross(dragDirection, transform.right);
// Lift + Drag = Total Force
rb.AddForce(liftDirection * lift - dragDirection * drag);
rb.AddForce(transform.forward * EnginePower);
}https://stackoverflow.com/questions/49716989
复制相似问题