How to get button input of oculus quest


I tried WebVR function for Oculus Quest. The displayed two controllers is Oculus Touch. These were well tracked.

But when I tried “onAAAStateChangedObservable” to get button input, just one pull of
left controller stick(red square in the below picture) generates over hundreds log per seconds.

All other buttons in both controllers has the same problem.

I think the problem includes two possible cases. One is failure of my code, the other is current babylon.js is not available for button input of Oculus Quest.

Here is my source code.

var canvas = document.getElementById("renderCanvas");

        var createScene = function () {
            var scene = new BABYLON.Scene(engine);
            var camera = new BABYLON.ArcRotateCamera('MainCamera1', 0, 0, 3, BABYLON.Vector3(0, 1.2, 0), scene, true);
            camera.position = new BABYLON.Vector3(0, 1.2, -1.1);
            camera.attachControl(canvas, true);
            var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
            var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
            //for VR
            var vrHelper = scene.createDefaultVRExperience();
            vrHelper.currentVRCamera.position.y = 300;

            const leftHand = BABYLON.Mesh.CreateBox("",0.1, scene);
            leftHand.scaling.z = 2;
            leftHand.isVisible =false;
            const rightHand = BABYLON.Mesh.CreateBox("",0.1, scene);
            rightHand.scaling.z = 2;
            rightHand.isVisible =false;

                    leftHand.position = vrHelper.webVRCamera.leftController.devicePosition.clone();
                    leftHand.rotationQuaternion = vrHelper.webVRCamera.leftController.deviceRotationQuaternion.clone();
                    vrHelper.webVRCamera.leftController.onPadStateChangedObservable.add(function (stateObject) {
                        console.error("left Pad state fn is called but not pushed"); 
                    rightHand.position = vrHelper.webVRCamera.rightController.devicePosition.clone();
                    rightHand.rotationQuaternion = vrHelper.webVRCamera.rightController.deviceRotationQuaternion.clone();

            return scene;

Any comments will be helpful for me.

I solved it by myself. My miss coding caused the problem.

I can get all key input of Oculus Quest controller. I’ll post a blog about basic controller input and provide the code to playground if need.


1 Like

Great to hear that it works, looking forward to the post and playground example.

Thanks for your comment .

A simple example is here.

I’ll modify my code and try to make it for playground.

Sorry for my late.

I set my code on playground. Try this with your oculus quest.

Usage : Press left/right controller of Oculus Quest. Scale of linked sphere or box is bigger