private Vector3 oldVector3;
private Vector3 newVector3;
private Quaternion oldQuaternion;
private Vector3 newRotatinForward;
初始化
oldVector3 = transform.position;
oldQuaternion = transform.rotation
計算
newVector3 = this.transform.position;
newRotatinForward = this.transform.forward;
float lenth = Vector3.Distance(oldVector3, newVector3);
Vector3 velocity = Quaternion.Inverse(oldQuaternion) * newRotatinForward;
float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;
Debug.Log(angle);