Unity的角度计算中是否有错误

问题描述 投票:0回答:1

我正在Unity中使用该功能

Quaternion.LookRotation(normal, (0,1,0));

您可以在https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html找到文档。如果法线平行于y轴,则应该是一个问题。由于无法创建由函数创建的坐标系,因此生成的四元数的方向围绕y轴旋转因此,我尝试使用

覆盖这种边缘情况
if(Vector3.Angle(normal, new Vector3(0, 1, 0)==0) ||Vector3.Angle(normal, new Vector3(0, 1, 0)==180)  )

[调试后,我意识到问题是每个Vector3.Angle(正常,新的Vector3(0,1,0)在170到180之间出现问题。我需要获得一个非常精确的方向,所以我的问题是你知道为什么吗这种不准确性正在发生,并且如何正确处理。谢谢!

unity3d vector geometry quaternions
1个回答
0
投票
Quaternion rot =
    Mathf.Abs(Vector3.Dot(normal.normalized,Vector3.up))<0.99f
    ? Quaternion.LookRotation( normal , Vector3.up )
    : Quaternion.identity;
© www.soinside.com 2019 - 2024. All rights reserved.