【问题标题】:Why does my camera clip into the player object when rotating around it?为什么我的相机在围绕播放器对象旋转时会夹在播放器对象中?
【发布时间】:2020-11-01 19:20:04
【问题描述】:

我正在尝试创建一个以固定距离环视玩家周围的相机。

我有很多,但是当水平旋转我的对象时,相机会夹到我的对象中。 以一定角度围绕对象旋转时不会发生这种情况(从上/下看)。

请注意,玩家视觉对象和相机跟随的目标不是视觉玩家对象的子对象。他们都是父母的孩子,可以独立移动。

                      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);
    }

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

干杯!

【问题讨论】:

    标签: c# unity3d cinemachine


    【解决方案1】:

    找到答案,我必须将播放器视觉添加到忽略碰撞列表中。 摄像头撞到了不同的播放器组件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-23
      • 2021-03-13
      • 1970-01-01
      • 2019-01-26
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多