How to add controller oculus quest in WebXR

Hello my controller XR with oculus can’t be accessed. I’m not usexrhelper but i migrate vr helper to xr helper. Here’s my code

var vrHelper = scene.createDefaultVRExperience({createDeviceOrientationCamera:false, useXR: true});

        vrHelper.enableInteractions();

        vrHelper.enableTeleportation({floorMeshName: "ground"});

        vrHelper.onAfterEnteringVRObservable.add(()=>{

            if(scene.activeCamera === vrHelper.vrDeviceOrientationCamera){

                BABYLON.FreeCameraDeviceOrientationInput.WaitForOrientationChangeAsync(1000).then(()=>{

                    // Successfully received sensor input

                }).catch(()=>{

                    alert("Device orientation camera is being used but no sensor is found, prompt user to enable in safari settings");

                })

            }

        });

vrHelper.onControllerMeshLoaded.add((webVRController)=>{

              webVRController.onSecondaryButtonStateChangedObservable.add((stateObject)=>{

                      if(webVRController.hand==="left"){

                          if(stateObject.pressed === true){

                              if(stateObject.pressed === true){

                                  gizmoManager.boundingBoxGizmoEnabled=true;

                              }else{

                                  gizmoManager.attachToMesh(null);

                          }

                      }

                  }else{

                          if(stateObject.pressed === true){

                              if(stateObject.pressed === true){

                                  if(stateObject.pressed === true){                            

                                      gizmoManager.attachToMesh(null);

                                      gizmoManager.boundingBoxGizmoEnabled=false;  

                                  }

                              }

                              }

                          

                      }

                  });

          });

I would recommend to fully migrate the code to XR. The documentation can be found here -

https://doc.babylonjs.com/how_to/introduction_to_webxr#migrating-from-webvr

You can see the further reading section for information about controllers etc’

1 Like

Thanks a lot, it help me :))

But there’s another problems :frowning_face:
I have add the teleportation code, but still can’t teleport in Oculus VR.

xrHelper.teleportation = xrHelper.baseExperience.featuresManager.enableFeature(BABYLON.WebXRFeatureName.TELEPORTATION, ‘stable’ /* or latest */, {
xrInput: xrHelper.input,
floorMeshes: [“ground”],
defaultTargetMeshOptions: {
teleportationFillColor: ‘#55FF99’,
teleportationBorderColor: ‘red’
} });

First - teleportation is enabled per default, you just need to provide the ground meshes to the experience helper. If you want to change the configuration, you can re-enable it (like you did).
Make sure that the “ground” mesh exists and is not in fact names differently. And make sure you teleport on the ground and not in any other place. Otherwise, it should work when pushing the thumbstick forward (and pointing at a ground).

but it can’t, my controller just turned to left and right, cant teleport

Want to share a playground?

its solved already about the teleport hehe, thank you so much.
my fault at floorMeshes: [ground].

1 Like