How do you update the WebXR camera if inside a moving elevator/space ship/car?

There are several scenarios where I would like to update a player’s position when they are in or on another mesh. For example a player steps onto an elevator platform, presses a button and then is lifted up with the platform. Or several players are on a ship and when the ship’s position is translated, all the riders move relative to the boat.

This resembles a classic parenting issue where the child is the webxr camera and the players can still teleport around on the ship but wherever the ship moves all the players are moved too. Maybe the child is not permanently parented, because I still want to allow the player to step off of the elevator and let the elevator go back down independently.

I tried to put together a parenting test in this playground but it doesn’t seem to work https://playground.babylonjs.com/#F41V6N#301

I parented the webxr camera to a sphere and then I lift the sphere, but the camera’s immersive POV doesn’t seem to move. I’m using the webxr emulator (haven’t tried this on the Quest yet)

Am I doing something wrong? Or maybe there is a better technique to do this?

Parenting an XR camera will be very confusing for the user. The minute you add rotation to the equation the entire scene will look incorrect. It is not technically disabled, but the internal teleportation mechanism (which allows you to move in XR) only works in local coordinates, as they are expected to be global (read this sentence 3 times, made sure it makes sense :-))

If you want to move an xr camera up an elevator, change the camera’s position along with the elevator. Something like this:

try parent webxr camera to moving object | Babylon.js Playground (babylonjs.com)

Another way is more complex but will provide better results - create a child where the camera is expected to be and copy its absolute position on each frame. Something like this:

try parent webxr camera to moving object | Babylon.js Playground (babylonjs.com)

Thanks! Will continuously copying the position information onto the xrcamera “fight” or override the device movement information? Wouldn’t it make it difficult to move freely (crouch down) while on a platform?

I checked with my quest before posting, this compensates the device’s real world position correctly.
What it does it practically a constant teleportation.

Kind of related. I do not need to do this soon, but want to have a toggle button named “Recliner Mode”, and another button “Adjust”.

While the user can move around the scene, they may just wish to recline back and watch the show, as if they were sitting upright. Is this sound possible? Would only want to adjustment the X Level when they toggle on or hit the “Adjust”, so minor changes would be reflected.

You should create a path and animate the camera accordingly. The relative position will be applied to it on each frame. The user will be able to move around in the real world, and it will reflect in the scene as well, but the relative point to the scene will change.

Ok, but just checking, the user will actually be in a chair reclined back. I just want them to not be looking at the ceiling. Is the animation, just a means to an end?

The user sitting in a chair looking at a certain point is your real world transformation. WebXR let’s you change the point relative to the scene in which the user is at. so changing the camera position 5 units forward will move them 5 units forward in the babylon scene plus it’s real world transformation. If you don’t want the user to look at the sky in the scene, you will need to rotate the camera correctly

Hi there.
I was following this thread today because I have the exact same problem.

I have a webxr camera that is constantly going in the z axis direction, no matter what is the rotation of my head. I want all rotation and head tracking preserved while constantly moving forward. Think about being in a train wagon, when I travel at the train speed, by I can stand or sit, or walking back and forth.

Actually changing only the z position of the camera during render is going to override any other position (e.g. the x, y positions are no more affected by head tracking, there’s is apparently no compensation at all).

In those playground examples I have the same problem, if you try to move the head left or right it won’t budge and you don’t see the object from different positions, the sphere is always at the center of the view. It’s like the entire positioning is messed up when the position is done both by headtracking and manual setting the variable.

Maybe it’s my chrome webxr simulator? I had the same problem with my game in quest 2 testing.

UPDATE: I think that this is the same requirement for games like Pistol Whip or similar. You have to dodge bullet and walls, but you always move forward at the same time. I know this can be done with an inverse approach where is the world that moves around you, but everything becomes a lot more complicated.

At its current state the WebXR camera cannot have a parent. This is mainly done so because we are taking the data coming straight from WebXR (position/rotation, view matrices etc’) and pass them directly to the WebXR camera. We can explore the possibility to add a parent to the camera, which will allow you to define the train wagon or the train itself as the parent of the camera. This way the camera itself stays in one position (and is updated by the device), but the train’s position that is constantly updated will change the user’s global position.

This issue was (supposed to be) fixed already, we will check that.

Hello. Any news?
I sorted out inverting the movements (centered camera against moving world), but if I’m to introduce physics, not sure what could happen!

Hi @Mizar01 ,

Moving the camera on each frame to emulate moving forward does work as expected. We are still working on allowing the XR camera to be parented to other components. I sadly can’t provide a timeline, but babylon 5.0 will have it for sure.

1 Like

Hi.
Thanks for the response, but as I see the examples you provided do not let the head move freely(you can move the head or walk but the camera always remains in the same world position, there’s no compensation), only rotation works.
As for now i’m not interested in parenting, as long as i can force basic position translation every frame on a specific axys.
Can you provide an example? Or maybe I can try to provide one counter example…