Guidance needed with "forward" with XR rotations

Many games allow you to define what your “forward” direction source is. This is usually your HMD or your left hand controller (or right, if you’re left handed). I’m trying to reproduce this in BabylonJS.

I have the following bit of code:

        if (this.disableTeleportation) {
            featureManager.disableFeature(WebXRFeatureName.TELEPORTATION);
            const smoothLocomotion = featureManager.enableFeature(WebXRFeatureName.MOVEMENT, 'latest', {
                xrInput: xr.input,
                floorMeshes: [this.scene.getMeshByName('ground1')!],
                customRegistrationConfigurations: swappedHandednessConfiguration,
                // add options here
                movementOrientationFollowsViewerPose: this.movementOrientationHMD,
                rotationAngle: this.movementRotationAngle
            }) as WebXRControllerMovement;
            smoothLocomotion.movementSpeed = this.movementSpeed;
        }

The full source for this test project is on github.

And the behavior I observe is that if movementOrientationFollowsViewerPose is set to true, then as I look left/right, my “forward” vector is whatever direction my headset is facing. :+1:

If I set movementOrientationFollowsViewerPose to false, my forward direction does not change with my headset. :+1: Now I can look one way and go “forward” in another, what many people call strafing.

What I’d like to do is be able to set my forward direction to that of my controller, the one I designated for customRegistrationConfigurations in the block of code above. Is that possible?

Tagging @RaananW for XRy stuff. :smiley:

You may want to @bigrig who was working on pulling controller accelerometer data a while back in XR.

Edit… Ah, found it: Move camera based on accelerometer data - #8 by bigrig

Oh, that would be a ncie feature! I am not sure it is fully supported in the movement feature yet.

You can set the movementOrientationFollowsViewerPose flag, but this is not entirely what you are looking for.

To achieve this right now (without making changes to the actual feature) you would probably need to implement the feature yourself.

I don’t mind looking into adding a flag to use the controller forward instead of the camera’s forward vector. I might find time next week to do that, though I am pretty busy as it is right now.

Sorry for not being able to provide a better or clearer answer here :-). This will require making interesting changes to the code - mainly ignoring the rotation set by the controller (as you have a new forward vector) and using only the controller’s orientation and the Y axis of the thumbstick.

Thinking about it again - yeah, it’s probably simpler than i thought. The controller can still decide what the orientation of the camera is, but the camera’s direction is not its forward. If you want to add a github issue for that I will be happy to look into that.

I’ve added [XR] Support controller as source of forward vector · Issue #14152 · BabylonJS/Babylon.js · GitHub. Initially, I thought just adding support for a controller to be forward would be best. But as I thought about it, allowing an arbitrary object might be a more flexible solution, providing support for things like vehicles where movement is completely disassociated with the HMD or the controllers. That may also be satisfied by setting HMD to false and I may be overthinking this.

1 Like