1.上下左右直接决定方向
void Update () {
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
if(Mathf.Abs(v)>0 ||Mathf.Abs(h)>0){
Vector3 desireDir = new Vector3(h,0,v);
Quaternion desireRotation = Quaternion.LookRotation(desireDir,Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation,desireRptation,Time.deltaTime*
rotateSpeed);
}
}
2.左右共同决定四个方向
void Update () {
private QuaterniondesireRotation =
Quaternion.LookRotation(transform.forward,Vector3.up);
if(Input.GetKeyDown(KeyCode.A)){
desireRot = Quaternion.LookRotation(-transform.right,Vector3.up);
}
if(Input.GetKeyDown(KeyCode.D)){
desireRot = Quaternion.LookRotation(transform.right,Vector3.up);
}
transform.rotation = Quaternion.Lerp(transform.rotation,desireRot,Time.deltaTime*rotateSpeed);
}
void
}
2.左右共同决定四个方向
void
}