【问题标题】:Unity3D Getting position of OVRCameraRigUnity3D获取OVRCameraRig的位置
【发布时间】:2022-05-05 12:49:13
【问题描述】:

我想将一个对象附加到 OVRCameraRig,然后使用它的位置,该位置与装备有偏移。

但是,无论耳机在哪里,我的对象始终是静态的。

这只发生在 OVRCameraRig 上。如果我使用普通的 MainCamera,我会得到正确的数据。但我没有了解 OVRCameraRig 的其他方面,例如楼层高度!

有什么方法可以获取 OVRCameraRig 的实际位置吗?

【问题讨论】:

  • 你能做到吗?我有一个类似的问题 - stackoverflow.com/questions/63831411/… 你认为你能回答这个问题吗?
  • 这个问题的答案被我接受了。所以,是的,我能够实现它。见下文。
  • 我试过了,但对我不起作用。我是 Unity 的新手,也许我在那里遗漏了一些东西。感谢您是否可以分享适合您的代码 sn-p。

标签: unity3d oculus


【解决方案1】:

Afaik OVRCameraRig 本身不动。

您可能想要得到的是centerEyeAnchor 的位置

// somehow get the reference e.g. using GetComponent
OVRCameraRig overCameraRig;

var position = overCameraRig.centerEyeAnchor.position;

无论usePerEyeCameras 的值如何,centerEyeAnchor 的位置总是会更新。

【讨论】:

  • 谢谢@derHugo。那行得通,并有所作为!非常令人困惑和不直观,因为我尝试了 OVRCameraRig 对象和 TrackingSpace 对象并且都返回了 vector3.zero 所以我没想到锚也会返回任何东西!
【解决方案2】:

尝试以下代码,使用centerEyeAnchor 属性获取OVRCameraRig 位置。

using UnityEngine;

public class OVRCameraPosTest : MonoBehaviour {
    
    [SerializeField] private OVRCameraRig overCameraRig;
    
    void Start() {
        Vector3 cameraPos = GetCameraPos();
        Debug.Log("Camera Position: " + cameraPos);
    }

    Vector3 GetCameraPos() {
        // Remove this line if you are refering the OVRCameraRig component 
        // through the inspector to the script.
        overCameraRig = GameObject.Find("OVRCameraRig").GetComponent<OVRCameraRig>();
        return overCameraRig.centerEyeAnchor.position;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多