Height issues with VR web XR

Hello everyone!

I need help with my PlayCanvas project, which is a simple demo training where you learn to use VR before entering the main scene I got a scene where you ask the user for permission to start the VR environment and a button that says “Get Immersed” when I click on it will activate the VR environment and everything is good so far.

This is the code that takes me to VR

if (this.app.xr.isAvailable(pc.XRTYPE_VR)) {
        if (window.DeviceOrientationEvent && window.DeviceOrientationEvent.requestPermission) {
            DeviceOrientationEvent.requestPermission().then(
                function(response) {
                    if (response == 'granted') {
                        window.addEventListener('deviceorientation', function (e) {
                            mainCameraTag.entity.camera.startXr(pc.XRTYPE_VR, pc.XRSPACE_LOCALFLOOR);
                            context.isVR = true;
                        }.bind(this));
                    }
                }.bind(this)).catch(console.error);
        } else {
            mainCameraTag.entity.camera.startXr(pc.XRTYPE_VR, pc.XRSPACE_LOCALFLOOR);
            context.isVR = true;
        }
    }

Obviously, all the references are working ok and I get to enter VR, the issue right now is with the height of the user, as you see I’m using XRSPACE_LOCALFLOOR, so the user height should start at 0 and then the offset will be given by the space of the headset to the ground (unlike XRSPACE_LOCAL that starts at the size of the object in 3D Space.

The issue is that the height of the camera will change depending on my actual height when I click the Get Immersed button (check the captures) in the first capture is how it should be when I enter VR Mode, and the second one is what happens if I click the Get Immersed button when I kneel down and the third one is when I click the button when I’m standing up, so you see the height never match the one that should be the correct one, and there’s no way to fix it through code, the only way to fix it is to Re-center the headset (Meta Quest 2 or Pico neo-pro 3) and that fixes the height. So my question is how to fix this automatically or via scripting, and if that is not a possibility, is there any way to call a re-center request via scripting?

Thanks in advance!

Hi @Josue_Soto,

What happens if you use pc.XRSPACE_LOCAL?

That’s what we are using in the following demo, we start the xr session from the regular player camera which is added as a child to the player controller. I think it respects the player jumping, giving the required offset to the VR camera, but I’m away from my VR headset right now to try:

https://solargames.io/demos/solar-xr-room