1
\$\begingroup\$

I'm looking for the functions to get the position and rotation data of the rift headset itself in Unity.

I have the Oculus integration SDK installed and want to avoid using any pre-fabs.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

you have an OVRCameraRig prefab in the scene then you can get the centerEyeAnchor transform as follows:

public OVRCameraRig cameraRig;

Vector3 headsetPosition = cameraRig.centerEyeAnchor.position;
Quaternion headsetRotation = cameraRig.centerEyeAnchor.rotation;

This holds the current position and rotation of the headset, and it always coincides with the average of the left and right eye poses.

If you don't want to use the default OVRCameraRig prefab you are gonna have to manually assign that property to the proper camera.

I hope this will help you!!

\$\endgroup\$
2
  • \$\begingroup\$ With public OVRCameraRig cameraRig; Vector3 headsetPosition = cameraRig.centerEyeAnchor.position; Quaternion headsetRotation = cameraRig.centerEyeAnchor.rotation; I get an output that looks like this (for example): (0.0, 1.0, -1.0, -2.0) Can you say what is what? It must be x,y,z and the quaternion but I can't say in which order.. \$\endgroup\$
    – 9Ilkp
    Commented Aug 25, 2021 at 10:11
  • \$\begingroup\$ @9Ilkp that's not a valid unit quaternion (it has length > 1). Unity prints quaternions in the order (x, y, z, w). Please note that the x, y, z components are NOT angles, and if you have to ask about the individual components of a quaternion, that's a good indication that you should not be using them. Try working with the quaternion as a whole, using the provided multiplication operator and helper methods, rather than trying to do math with individual components. Avoiding component-wise math will tend to lead you to code that is clearer to read and more likely to be correct. \$\endgroup\$
    – DMGregory
    Commented Aug 25, 2021 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .