How to assign other controller Buttons on VR controllers

What would be the right way to assign other VR controller buttons?

For trigger-button I would use:

What would be the right name for example for “A” button? If I remember it correct, “A” is not occupied by other needle VR functions like scale

Original Post on Discord

by user 743203108271816774

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hello Krempel. To assign other VR controller buttons, you can typically reference methods similar to those used for the “selectionDown” event. However, based on the information provided, it seems that WebXRController only exposes the specific events selectionDown, selectionUp, selectionPressed, and selectionClick (see the documentation).

For other buttons like the “A” button, you would have to handle them in a similar manner, provided that there are corresponding methods or properties exposed by WebXRController. If such methods or properties are not documented, you may need to listen for specific input events in the XR input source (XRInputSource), which is part of the WebXR API.

Unfortunately, without additional information provided in the documentation you’ve supplied, I can’t give you the exact name or method for the “A” button. It’s possible that the documentation has more details on this, or that you may need to rely on the underlying WebXR Device API directly for non-generic buttons.

As it stands, Needle Engine’s provided types documentation exposes the following relevant properties and methods related to the trigger button on the VR controller:

  • selectionDown: Returns true when the selection button (typically a trigger) is pressed down.
  • selectionUp: Returns true when the selection button is released.
  • selectionPressed: Returns true if the selection button is currently being pressed.
  • selectionClick: Detects a click, a quick press and release, of the selection button.

For more specific buttons like the “A” button on a particular controller, you might need to interact with the input property of WebXRController, which is an instance of XRInputSource, and handle its gamepad attribute accordingly.

1 messages left GPT 4

Hi @krempel what the bot suggests should work. There are also some options to disable default behaviour of the WebXRControllers on the WebXRController class itself

Note that we’re currently working on a WebXR system update which will enable you to work with WebXR much more easily (and will also remove the need for any hacks)

Thanks :slightly_smiling_face:
@elZach helped me and used this:

const clicked = this.webXR.Controllers[this.controllerIndex].input?.gamepad?.buttons[this.buttonIndex].pressed;

I will apply my function to the B button :slightly_smiling_face:

and here are the buttonIndexes numbers (in case somebody else will need this):
1 - Grab-Button
4 - “A”
5 - “B”

by user 743203108271816774

Great - You can find the button maps for xr input sources here:

This is also exactly one of the things that will become easier too:

  • no need to use arbitrary indices anymore - instead you’ll be able to just query the button with getButton("x-button") once the update is done :slightly_smiling_face: