Hello,
I have a problem on my Oculus Rift S on which I work. I’m using an XR Rig in my scene but when I click on play the camera of my XR Rig is shifted on the X and Z axis so I’m not centered properly and to fix this I have to go in the pause menu of Oculus and reset the view manually. I would like a method to reset the view directly in the code at start or understand where this offset comes from.
2 Answers
2I use this for Rift and Rift S in a sitting/standing game, but for Quest it has no effect (because you are supposed to recenter by holding down a menu button I think).
using UnityEngine.XR;
using UnityEngine.InputSystem;
float fRecenterTimer = 0.0f;
bool bTrackingOriginSet = false;
void Update()
{
//recenter logic
UnityEngine.XR.InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
if (!bTrackingOriginSet) //always do once
{
if(headDevice!=null && headDevice.isValid)
{
headDevice.subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Device);
bTrackingOriginSet = true;
}
}
if (Menu.bRecenter) //replace with your own bool
{
fRecenterTimer += Time.unscaledDeltaTime;
if (fRecenterTimer > 3.0f)
{
if(headDevice!=null && headDevice.isValid)
{
headDevice.subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Device);
headDevice.subsystem.TryRecenter();
}
Menu.bRecenter = false;
fRecenterTimer = 0.0f;
}
}
}
@rh_galaxy Thank you very much for your help but unfortunately it does not work for me I always have this offset on the camera compared to the position of the XRrig.