以下实现的是一个2D垂直视角汽车的控制
private void MoveUpdate(){
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (v != 0 || h != 0)
{
rigibody.velocity = Direction=new Vector2(h,v);
targetAngle =Vector2.Angle(Vector2.down,Direction);
if (h < 0f)//targetAngle只会取得0-180,所以在左边取负
{
targetAngle =-targetAngle;
}
}
currentAngle=Mathf.LerpAngle(currentAngle,targetAngle,RotateSpeed* Time.deltaTime);
RotationTransform.localRotation=Quaternion.Ang