unity中有计算两个向量的接口Vector3.Angle ,但是该接口只能返回0-180度,有时候很难满足具体的项目需求所以我就自己动手写了一个方法,亲测有效:
public float Angle_360(Vector3 from_, Vector3 to_)
{
Vector3 v3 = Vector3.Cross(from_, to_);
if (v3.y > 0)
return Vector3.Angle(from_, to_);
else
return 360 - Vector3.Angle(from_, to_);
}
这里值得注意的是v3.y 这个只适用于xz平面的两个向量,因为我这里应用于地面两个向量所以事v3.y。
unity 如何实现返回两个向量的夹角(0-360度)
最新推荐文章于 2024-03-08 16:23:27 发布