Unity 入门 物理系统中 添加力

 1.Rigidbody.AddForce

 2. Rigidbody.AddRelativeForce

 3.Rigidbody.AddTorque
 4.Rigidbody.AddRelativeTorque




    public GameObject forcePosition;
    // Use this for initialization
    void Start () {

        this.GetComponent().AddForceAtPosition(this.transform.right, forcePosition.transform.position, ForceMode.Impulse);
    }
    
    // Update is called once per frame
    void Update () {
    
    }




//把本身进行添加的时候 同时加其他一些组件
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(AddForce))]
public class AddTorque : MonoBehaviour {

    // Use this for initialization
    void Start () {

        //this.transform.Rotate()
        //扭矩 在参数的向量方向上旋转
        this.GetComponent().AddTorque(Vector3.up * 10);
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

你可能感兴趣的:(Unity 入门 物理系统中 添加力)