The idiot's guide to oculus quest controls

Hi There,

I am trying to learn more about how to fire off a simple function if I hit A or B on the quest controller. Is there boilerplate code for that somewhere? The documentation that I found is this: WebXR Input and Controller support - Babylon.js Documentation , but I wonder what else is out there?

Best,
AKSG

Hope this doc will help you.

https://doc.babylonjs.com/how_to/webxr_demos_and_examples

The documentation page you found is the right one, and details the basic webxr controller concepts and how they are implemented in babylon.

Would be great to know what is missing or what makes this page not complete!

And, if you have a specific use case, describe it here, I am sure we can help.

1 Like
const triggerComponent = motionController.getComponent("xr-standard-trigger");
if (triggerComponent) {
    // found, do something with it.
}

It looks to me like this is the code for, if you press the trigger button, do a thing, yes? If this is as simple as I think it is, that’s great. I’ll just figure out how to replace standard trigger with A and B, so that I can trigger the functions that I need.

See, now I know what’s missing :slight_smile:

You can get a list of available components, and see what component you can get. Those are standard strings, so you can reuse the same components with other controllers.

//XR-way of interacting with the controllers for the left hand:
xr.input.onControllerAddedObservable.add(controller => {
  controller.onMotionControllerInitObservable.add(motionController => {
    if (motionController.handness === "left") {
      motionController
        .getMainComponent()
        .onButtonStateChangedObservable.add(component => {
          if (component.changes.pressed) {
            if (component.pressed) {
                console.log("hi");
                POV=false;
            }}})}})});
        xr.input.onControllerAddedObservable.add(controller => {
  controller.onMotionControllerInitObservable.add(motionController => {
    if (motionController.handness === "right") {
      motionController
        .getMainComponent()
        .onButtonStateChangedObservable.add(component => {
          if (component.changes.pressed) {
            if (component.pressed) {
                console.log("hi");
                POV=true;
            }}})}})});

This is me just hacking the physics controller; I still haven’t figured out how to press buttons yet, but I’m getting there.

press the A and B buttons I should say