Responsive, single button input in A-Frame WebVR

611 Views Asked by At

For my A-Frame WebVR game, I need to access a single "controller" button, regardless of platform. For a phone using a magic window or Google Cardboard, any screen tap would count. For Gear VR or Daydream, any button on the controller would count. For a PC VR rig, any button on either controller would count.

Don McCurdy's universal-controls (https://github.com/donmccurdy/aframe-extras/tree/master/src/controls) would seem to be relevant, yet it's not clear how I could use it to do what I want.

I could also go access the GamePad API directly, and separately detect screen taps.

What's the best way to proceed?

2

There are 2 best solutions below

0
Noam Almosnino On BEST ANSWER

Perhaps the input mapping system, from Fernando Serrano could help: https://blog.mozvr.com/input-mapping/

0
Doug Reeder On

It turns out, if you want to treat all buttons alike, it's easier to listen for the buttonchanged event on the controls entity.

As Noam kindly pointed out, aframe-input-mapping-component is great for general mapping of buttons to actions.

[edit] I've created aframe-button-controls to handle this.