如何在unity3d中给物体增加扭矩力

来源: 2020-12-11 20:49:19      点击:
using UnityEngine;
using System.Collections;

public class AddTorqueExample : MonoBehaviour
{
    public float amount = 50f;
    
    
    void FixedUpdate ()
    {
        float h = Input.GetAxis("Horizontal") * amount * Time.deltaTime;
        float v = Input.GetAxis("Vertical") * amount * Time.deltaTime;
        
        rigidbody.AddTorque(transform.up * h);
        rigidbody.AddTorque(transform.right * v);
    }
}