Search code examples
unity-game-enginevirtual-realityoculusquest

Headset position always returns zero in Oculus Quest with Unity and Oculus SDK


I am using the Oculus Quest with Unity 2018.4.22f1 and Oculus SDK. Moving into my application works well. But every time I want to get the position of the headset, the vector zero is returned.

I tried these solutions :

OVRPose tracker = OVRManager.tracker.GetPose();
return tracker.position;

And

GameObject camera = GameObject.Find("OVRCameraRig");
return camera.transform.position;

This is position tracking setup:

enter image description here

Do you have any idea how to get the headset position?


Solution

  • When I want to get the headset's position, I am using the transform.position of the CenterEyeAnchor which is inside OVRPlayerController/OVRCameraRig/TrackingSpace.

    using UnityEngine;
    
    public class YourScriptNameHere : MonoBehaviour
    {
        GameObject centerEye;
        Vector3 headsetPos;
    
        void Start(){
            centerEye = GameObject.Find("CenterEyeAnchor");
        }
    
        void Update(){
            headsetPos = centerEye.transform.position;
        }
    }