微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我的相机在旋转时会夹入播放器对象?

如何解决为什么我的相机在旋转时会夹入播放器对象?

我正在尝试创建一个以固定距离看向播放器的摄像机。

我有一个不错的选择,但是当水平旋转我的物体时,相机会夹入我的物体。 当以一定角度围绕对象旋转时(从上/下看),不会发生这种情况。

请注意,播放器视觉对象以及摄像机所遵循的目标不是视觉播放器对象的子级。他们都是父母的孩子,可以独立移动。

                      PlayerParent
                           |
           ==================================
           |                                |
       PlayerVisual                      CameraTarget

我真的不知道为什么会这样。

void Start()
    {
        _camera = GetComponent<CinemachineVirtualCamera>();
    }

    // Update is called once per frame
    void Update()
    {
        RotateHorizontal();
        RotateVertical();
    }

    void RotateVertical()
    {
        var _rotationPower = 2f;

        _camera.Follow.rotation *= Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * _rotationPower,Vector3.right);

        var angles = _camera.Follow.eulerAngles;
        angles.z = 0;

        var angle = _camera.Follow.eulerAngles.x;

        //clamp rotation.
        if (angle > 180 && angle < 340)
        {
            angles.x = 340;
        }
        else if (angle < 180 && angle > 40)
        {
            angles.x = 40;
        }

        _camera.Follow.eulerAngles = new Vector3(angles.x,_camera.Follow.eulerAngles.y,0);
    }

    void RotateHorizontal()
    {
        var _rotationPower = 2f;
        _camera.Follow.Rotate(new Vector3(0,Input.GetAxis("Mouse X") * _rotationPower,0),Space.Self);
    }

任何有助于理解为什么发生这种情况的帮助都非常有用!

干杯!

解决方法

找到了答案,我不得不将玩家视觉添加到忽略碰撞列表中。 相机碰到了不同的播放器组件。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。