【问题标题】:Simulate Real Car Rotation In Unity3D在 Unity3D 中模拟真实的汽车旋转
【发布时间】:2019-11-23 07:55:21
【问题描述】:

我创建了一个 3D 赛车,汽车左右移动,但它不会像真车一样旋转。 以下是我的脚本:

public class movement : MonoBehaviour {
     Rigidbody rb;
    public float forwardforce = 600f;
    public float sidwayforce;
    float left_right;
     public float thrust;
    public float speed;
    void Start () {
        rb = GetComponent<Rigidbody>();
    }
    // Update is called once per frame
    void FixedUpdate () {
       rb.AddForce(0, 0, forwardforce *Time.deltaTime);
  Controll ();
        left_right = Input.GetAxis("Horizontal");

            // rb.AddForce(sidwayforce* left_right * Time.deltaTime, 0, 0,ForceMode.VelocityChange);
       // rb.AddForce( sidwayforce*left_right * Time.deltaTime, 0, 0, ForceMode.Acceleration);
        //rb.velocity = new Vector3(sidwayforce*left_right * Time.deltaTime,0,0); 
    }

这是左右移动的代码,但我想创建汽车旋转

    void Controll (){
        if (Input.GetAxis ("Horizontal") > 0) {
            rb.AddForce (20f, 0, 0);
        } else {
            if (Input.GetAxis ("Horizontal") <0) {
                rb.AddForce (-20f, 0, 0);
            }
        }
    }
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    如果您想要逼真的汽车运动,我建议使用车轮碰撞器。车轮碰撞器可用于控制加速/减速以及转弯,因此它们将创建更逼真的汽车运动(只要您正确设置车轮属性,它们可能会有点挑剔)。

    如果您点击这些链接,它们将更详细地解释轮式对撞机的工作原理以及您如何对其进行编程

    https://docs.unity3d.com/Manual/WheelColliderTutorial.html

    https://docs.unity3d.com/Manual/class-WheelCollider.html

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 2012-11-09
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多