[Unity 3D] 求两个向量间的夹角的方法
程序员文章站
2022-03-02 09:29:30
...
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;