Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的相机在旋转时会卡入播放器对象?_C#_Unity3d_Cinemachine - Fatal编程技术网

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

C# 为什么我的相机在旋转时会卡入播放器对象?,c#,unity3d,cinemachine,C#,Unity3d,Cinemachine,我正在尝试创建一个摄像头,可以在固定距离内观察玩家周围 我有一个很好的位置,但是当水平旋转我的物体时,相机会夹在我的物体上。 以一定角度(从上/下看)围绕对象旋转时不会发生这种情况 请注意,播放机可视对象和相机所跟踪的目标不是可视播放机对象的子对象。他们都是父母的孩子,可以独立移动 PlayerParent | =================================

我正在尝试创建一个摄像头,可以在固定距离内观察玩家周围

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

请注意,播放机可视对象和相机所跟踪的目标不是可视播放机对象的子对象。他们都是父母的孩子,可以独立移动

                      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);
    }
void Start()
{
_摄像头=GetComponent();
}
//每帧调用一次更新
无效更新()
{
旋转水平();
旋转的();
}
空穴旋转()
{
var _旋转功率=2f;
_camera.Follow.rotation*=四元数.AngleAxis(Input.GetAxis(“鼠标Y”)*\u rotationPower,Vector3.right);
变量角度=_camera.Follow.eulerAngles;
角度z=0;
变量角度=_camera.Follow.eulerAngles.x;
//夹具旋转。
如果(角度>180和角度<340)
{
角x=340;
}
否则如果(角度<180和角度>40)
{
角度x=40;
}
_camera.Follow.eulerAngles=新矢量3(角度.x,_camera.Follow.eulerAngles.y,0);
}
空心旋转水平()
{
var _旋转功率=2f;
_camera.Follow.Rotate(新的Vector3(0,Input.GetAxis(“鼠标X”)*\u rotationPower,0),Space.Self);
}
任何有助于理解为什么会发生这种情况的帮助都是非常值得的


干杯

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