unity3d 这个鼠标的外观功能有什么问题吗?

wpcxdonn  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(128)

我已经反复尝试了几个星期了,但是它还是坏了,所以我想我应该寻求一些帮助。除了一个明显的问题之外,它的表现和预期的一样:输出灵敏度看起来是超音调相关的。
`

//Grab mouse input
        float rotateHorizontal = Input.GetAxis("Mouse X");
        float rotateVertical = -Input.GetAxis("Mouse Y");

        Vector3 rotation = new Vector3(rotateVertical, rotateHorizontal, 0);

        transform.Rotate(sensitivity * Time.deltaTime * rotation);

        Vector3 eAngles = transform.eulerAngles;
        float pitch = eAngles.x;
        pitch = ClampAngle(pitch, -camClamp, camClamp); 
        transform.localEulerAngles = new Vector3(pitch, eAngles.y, eAngles.z);

`
我错过了什么?我很肯定这不是夹角功能,因为我从一个有信誉的来源偷来的。谢谢你的帮助。

roejwanj

roejwanj1#

旋转很难!我认为这是一个旋转顺序问题。切换到四元数,问题仍然存在,然后找到this可爱的线程,并重新排序操作数。

originalRotation = transform.localRotation;
    //Grab mouse input
    float rotateHorizontal = Input.GetAxis("Mouse X");
    float rotateVertical = Input.GetAxis("Mouse Y");

    Quaternion xQuaternion = Quaternion.AngleAxis(rotateHorizontal, Vector3.up);
    Quaternion yQuaternion = Quaternion.AngleAxis(rotateVertical, -Vector3.right);

    transform.localRotation = xQuaternion * originalRotation * yQuaternion;

    Vector3 eAngles = transform.eulerAngles;
    float pitch = eAngles.x;
    pitch = ClampAngle(pitch, -camClamp, camClamp); 
    transform.localEulerAngles = new Vector3(pitch, eAngles.y, eAngles.z);

谢谢你freya holmer
四元数乘法中的顺序很重要!

相关问题