[Unity 3D] 求两个向量间的夹角的方法

1、

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
float angle = Vector3.Angle(d1, d2);

2、

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
float dot = Vector3.Dot(d1, d2.normalized);     //d2.normalized向量归一化
float angle = Mathf.Acos(dot) * Mathf.Rad2Deg;

3、

Vector3 d1 = transform.forward;
Vector3 d2 = new Vector3(0,3,0);
Vector3 cross = Vector3.Cross(d1, d2.normalized);
float angle = Mathf.Asin(Vector3.Distance(Vector3.zero, cross)) * Mathf.Rad2Deg;

 

你可能感兴趣的:(Unity,3D,Unity,3D)