Unity3D获取OVRCameraRig的位置
Unity3D Getting position of OVRCameraRig
我想将一个对象附加到 OVRCameraRig,然后使用它的位置,该位置与装备有偏移。
但是,无论耳机在哪里,我的对象始终是静态的。
这只发生在 OVRCameraRig 上。如果我使用普通的 MainCamera,我会得到正确的数据。但我没有了解 OVRCameraRig 的其他方面,例如地板高度!
有什么方法可以获取 OVRCameraRig 的实际位置吗?
据我所知,OVRCameraRig
本身不会移动。
您可能想要得到的是 centerEyeAnchor
而不是
的位置
// somehow get the reference e.g. using GetComponent
OVRCameraRig overCameraRig;
var position = overCameraRig.centerEyeAnchor.position;
无论 usePerEyeCameras
的值如何,centerEyeAnchor
的位置总是更新。
尝试使用以下代码使用 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;
}
}
我想将一个对象附加到 OVRCameraRig,然后使用它的位置,该位置与装备有偏移。
但是,无论耳机在哪里,我的对象始终是静态的。
这只发生在 OVRCameraRig 上。如果我使用普通的 MainCamera,我会得到正确的数据。但我没有了解 OVRCameraRig 的其他方面,例如地板高度!
有什么方法可以获取 OVRCameraRig 的实际位置吗?
据我所知,OVRCameraRig
本身不会移动。
您可能想要得到的是 centerEyeAnchor
而不是
// somehow get the reference e.g. using GetComponent
OVRCameraRig overCameraRig;
var position = overCameraRig.centerEyeAnchor.position;
无论 usePerEyeCameras
的值如何,centerEyeAnchor
的位置总是更新。
尝试使用以下代码使用 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;
}
}