使用 RotateAround 从前到后更改时,X 轴反转

X-axis is inverted when changing from front to behind using RotateAround

我正在使用垫子来控制一个对象围绕另一个对象的旋转。 我要解决的第一个问题是,在使用RotateAround时,当我从前到后变化时,x轴是倒转的。

我用这个修复了它:

if (lookAtItem.position.z - camera.transform.position.z > 0)
        {

            camera.RotateAround(lookAtItem.position, Vector3.right, _ComandValues[5] * _RightStickScale);
        }
        else
        {
            camera.RotateAround(lookAtItem.position, Vector3.left, _ComandValues[5] * _RightStickScale);
        }

我只是使用位置来了解我是在给定对象的后面还是前面。

现在第二个问题出现了:

lookAtItem.position.z - camera.transform.position.z在0附近并且我尝试绕x轴旋转时,程序从lookAtItem.position.z - camera.transform.position.z > 0lookAtItem.position.z - camera.transform.position.z < 0的变化太快,使相机疯狂(我正在旋转相机)。

那么有人知道发生了什么事吗?

好的,所以我在提出问题后2分钟修复了它。 -_-

请注意,我只能使用此解决方案,因为相机有一个观察脚本,其中的项目作为目标旋转(如果你没有,你必须在正交基础上哭很多)。

解决方案:

将代码替换为:

camera.position += camera.transform.up * _LeftStickScale * _ComandValues[5]