'Unity3D Getting position of OVRCameraRig

I want to attach an object to the OVRCameraRig and then use its position, which is offset from the rig.

However, my object is always static, irrespective of where the headset is.

This only happens with the OVRCameraRig. If I use a normal MainCamera I get the right data. But I'm not getting other aspects, like floor level, of the OVRCameraRig!

Is there some way to get the actual position of the OVRCameraRig?



Solution 1:[1]

Afaik the OVRCameraRig itself doesn't move.

What you probably want to get is the position of the centerEyeAnchor instead

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

var position = overCameraRig.centerEyeAnchor.position;

Regardless of the value of usePerEyeCameras the centerEyeAnchor's position is always updated.

Solution 2:[2]

Try the following code to get the OVRCameraRig position using the centerEyeAnchor attribute.

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 derHugo
Solution 2 Codemaker