C# 我可以使用刚体。不漂移的附加力吗?

C# 我可以使用刚体。不漂移的附加力吗?,c#,unity3d,rigid-bodies,C#,Unity3d,Rigid Bodies,我正在尝试创建一个飞行模拟器,使用刚体。我用外力使飞机加速。但是,当旋转平面时,会有很多漂移。我怎样才能阻止这一切 using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlaneController : MonoBehaviour { public float maxSpeed = 200f; public float speed = 90.0f;

我正在尝试创建一个飞行模拟器,使用刚体。我用外力使飞机加速。但是,当旋转平面时,会有很多漂移。我怎样才能阻止这一切

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlaneController : MonoBehaviour
{
    public float maxSpeed = 200f;
    public float speed = 90.0f;
    public Vector3 rotationSpeedY = new Vector3(0, 0, 40);
    public Vector3 rotationSpeedZ = new Vector3(40, 0, 0);
    public Rigidbody rb;


    private void FixedUpdate()
    {
        rb.AddRelativeTorque(-Input.GetAxis("Horizontal") * rotationSpeedY * Time.deltaTime);

        rb.AddRelativeTorque(Input.GetAxis("Vertical") * rotationSpeedZ * Time.deltaTime);

        rb.AddRelativeForce(transform.forward * speed);

        speed -= transform.forward.y * Time.deltaTime * 50.0f;

        if (rb.velocity.magnitude > maxSpeed)
        {
            rb.velocity = rb.velocity.normalized * maxSpeed;
        }

        if (speed < 35.0f)
        {
            speed = 35.0f;
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类PlaneController:MonoBehavior
{
公共浮点数maxSpeed=200f;
公共浮子速度=90.0f;
公共向量3旋转速度=新向量3(0,0,40);
公共向量3旋转速度=新向量3(40,0,0);
公共刚体;
私有void FixedUpdate()
{
rb.AddRelativeTorque(-Input.GetAxis(“水平”)*旋转速度*时间增量);
rb.AddRelativeTorque(输入.GetAxis(“垂直”)*旋转速度*时间.deltaTime);
rb.添加相对力(transform.forward*速度);
速度-=变换.前进.y*时间.deltaTime*50.0f;
如果(rb.velocity.magnitude>maxSpeed)
{
rb.velocity=rb.velocity.normalized*maxSpeed;
}
如果(速度<35.0f)
{
速度=35.0华氏度;
}
}
}

原因是您没有以任何方式对空气动力学进行建模。当一架真正的飞机倾斜时,机翼根据其迎角与飞行方向提供升力,同时产生相反方向的阻力

如果你想让你的飞机像真实世界一样反应,你必须计算这两种力,如果你不想根据机翼形状寻找精确的空气动力学模型,这将非常简单。现在你的飞机好像没有大气层