Lock WebXR head position on Y-axis?

I’m implementing VR via WebVR in my game which has a third person character controller.

I’m trying to figure how to limit the camera/VR head position so when a player crouches with headset it doesn’t move the camera to that relative Y position change.

I’ve tried referencing this.app.xr.camera.setPosition() and only changing the Y with no luck.

I don’t want players seeing through their character mesh, nor do I want the player looking through the character’s knees.

How would I go about limiting the VR head movement considering the Y-axis so crouching in real-time has no effect via client?

I also have a reference to the Head of the character mixamo rig, would binding the XR camera’s Y position to the Head position Y help?

Assuming you have a parent to the Camera, you can move the parent by the amount that the player has moved on the Y axis to negate their Y movement

1 Like

Hmm this sounds like what I’ve been attempting for that past few hours:

    // Change 'Camera Axis' Y-axis position for XR/VR        
    this.cameraAxis.setPosition(this.playerHead.getPosition().x, this.playerHead.getPosition().y - 1.18, this.playerHead.getPosition().z + 0.18); // first-person
    this.cameraAxis.setEulerAngles(0, 90, 0);
    
    // Lock XR/VR head position applied to camera
    this.app.xr.camera.setPosition(this.playerHead.getPosition().x, this.playerHead.getPosition().y, this.playerHead.getPosition().z);

Considering the code above, how would I do just that considering this.cameraAxis as the parent to the camera @yaustar?

this.cameraEntity references the XR camera parent yet I’m using this.playerHead

Without knowing your entity setup I don’t know.

Taking the setup here : WebXR Hello World | Learn PlayCanvas

image

I would have a height that I always want the VR camera to be (e.g 8)

Take the world position of the VR camera (e.g 5)

Set the Camera Offset entity Y position to negate it (8 + (8-5) = 11).

1 Like

Thanks, this clarified a bit more.

Yet this being the .getPosition().y value of the camera entity correct?

Yes

1 Like

So I attempted implementing the equation with proper variables, still no luck locking the Y-axis position.

Would I need to add it to an update function or is a event listener good enough?

I would be doing in update or even postUpdate.

1 Like

You could offset parent entity position by local position of camera - which is based on XR tracking.

But. This can lead to VR sickness as will lead to desync between real world position and what brain expects to happen in VR.
Generally in VR you want to avoid any modifications and limitations to motion, otherwise to the player it feels “disconnected”.

1 Like

I figured I shouldn’t change it yet it was an attempt to prevent players from crouching and being able to see within their character model. Most VR games toggles a crouch animation if the player happens to do so in the real world.

I’m still testing various ways to go about it, I even disabled the character model itself in some instances.

1 Like