如何统一进行逼真的平面运动

时间:2020-02-17 18:57:20

标签: unity3d

我目前的平面运动对于第一次迭代是可以的,除了我无法绕过如何进行有效的横摇运动。我需要的是,当您使用堤岸上的向上箭头向上倾斜时,应使其沿与堤岸所成角度相同的方向倾斜。忽略Propeller变量,该变量将在以后进行处理。

在这里输入我的代码

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

public class movement : MonoBehaviour
{
public GameObject plane;
public Rigidbody rb;
public float thrust = 100f;
public GameObject propeller;

void Update()
{

    if (Input.GetKey("left"))
    {
        plane.transform.Rotate(0, 0, 1, Space.World);
    }
    if (Input.GetKey("right"))
    {
        plane.transform.Rotate(0, 0, -1, Space.World);
    }
    if (Input.GetKey("space"))
    {
        rb.AddForce(transform.forward * thrust);
    }
    if (Input.GetKey(KeyCode.LeftControl))
    {
        rb.velocity = Vector3.zero;
        rb.angularVelocity = Vector3.zero;
    }
    if (Input.GetKey("down"))
    {
        plane.transform.Rotate(-1, 0, 0, Space.World);
    }
    if (Input.GetKey("up"))
    {
        plane.transform.Rotate(1, 0, 0, Space.World);
    }
}

}

1 个答案:

答案 0 :(得分:0)

我建议查看此链接https://docs.unity3d.com/ScriptReference/Rigidbody.AddTorque.html

它帮助我学习了如何在学校的项目中制作滚球。

增加扭矩将使圆形物体产生线性运动。

这里有个例子

rb.AddTorque("the force in the x axis", the force in the y-axis, "the force int the z axis,"the force mode")