I’m working with the new XR module.
There is an event for a “select”, which could be pressing a trigger button, or touching a screen. But there’s no event for the other possibles buttons that the XrInputSource can have.
See Playcanvas’s documentation
In fact, I can do something like this:
Controller.prototype.update = function(dt) {
// gamepad input
var gamepad = this.inputSource.gamepad;
if (gamepad) {
if(gamepad.buttons[0].touched)
{
//Touched event on button 0
}
if(gamepad.buttons[0].pressed)
{
//Pressed event on button 0
}
}
But I don’t like the fact that I’m looking in update for buttons states change and managing all that stuff (ie: if it was pressed last frame and still pressed, do nothing…and so on).
My suggestion is to put that logic into the engine. I want to handle a button event, receive an event object telling me which button generate the event, if its a touched or pressed event and the percentage of press if it’s a trigger.