欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[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;

 

相关标签: Unity 3D