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

public class AddForce : MonoBehaviour
{
public ForceMode f;
private Rigidbody r;
public float Rtspeed = 1000;
private void OnMouseDown()
{
r.AddForce(Vector3 .right * 500, f );//世界坐标系添加力,给世界方向 => 世界方向
//r.AddForce(transform .right * 500, f);//世界坐标系添加力,给自身方向 => 自身方向
//r.AddRelativeForce(Vector3.right * 500,f);//自身坐标系添加力,给世界方向 => 自身方向
//r.AddRelativeForce(transform .right * 500, f);//无效果的错误使用
r.useGravity = true;
}

// Start is called before the first frame update
void Start()
{
    r = transform.GetComponent<Rigidbody>();
}

// Update is called once per frame
void FixedUpdate()
{
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");

    r.AddTorque(transform.up * v*Rtspeed );
    r.AddTorque(Vector3 .right * h*100);
    
    //使用刚体组件移动
   if (Input.GetKey(KeyCode.Z))
    {
        //每帧移动固定距离
        r.MovePosition(transform.position + Vector3 .left *0.2f);

        //添加在方向上(自身/世界)添加固定加速度
        //r.velocity = new Vector3(h*speed*Time.deltaTime,0 ,0);
        //r.velocity = transform .forward  * 3;
    }



}

}