public class TankMovement : MonoBehaviour {
//设置一个移动速度
public int speed = 5;
private Rigidbody rigidbody;
//设置一个角速度
private int angularSpeed = 10;
// Use this for initialization
void Start () {
rigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
}
//固定帧调用,一般使用场景为物理移动
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
//垂直方向W S 为前后移动
float v = Input.GetAxis("Vertical");
//刚体自身设置一个移动速度,transform.forward代表自身的前方向移动,
rigidbody.velocity = transform.forward * v * speed;
// 刚体自身设置一个角速度
rigidbody.angularVelocity = transform.up * h * angularSpeed;
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容