在SteamVR中使用场景相机射线导致偏移的问题

【SteamVR】中使用场景Camera射线有偏移的情况,或者说场景相机通过鼠标位置获取物体时,射线位置偏差很大的情况

背景:一个项目中要使用SteamVR模式+PC模式,在PC模式下,使用鼠标射线出现了很大的偏差:
实例:

 private void FixedUpdate()
    {
    
    
        if (Input.GetKey(KeyCode.LeftControl))
        {
    
    
            if (!raycastCamera) raycastCamera = GetComponent<Camera>();
            Ray ray = raycastCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
    
    
                Debug.Log("当先选中物体:" + hit.transform.name);
                Debug.DrawLine(raycastCamera.transform.position, hit.point, Color.red);
                if (!PointSphere)
                {
    
    
                    PointSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    PointSphere.transform.localScale = Vector3.one * 0.3f;
                    PointSphere.GetComponent<MeshRenderer>().material.color = Color.red;
                    PointSphere.GetComponent<Collider>().enabled = false;
                }
                PointSphere.transform.position = hit.point;
            }
        }
    }

然后出现了这种情况:
在这里插入图片描述
然后发现关闭OpenVR Loader 就恢复了正常,但是要用SteamVR时必须开启这个(暂时没找到对应API),
随后想到应该是相机的问题:
在这里插入图片描述
将TargetEye 设置为 None(Main Display)即可恢复正常

猜你喜欢

转载自blog.csdn.net/qq_41125597/article/details/129733545
今日推荐