[SOLVED] Gamepad input

Hello, all
I have been looking at gamepad stuff, (GitHub and playcanvas) But I can’t get I to work. All I need is how to get when buttons are pressed. I am using an Xbox controller so Y/B/A/X or as this website says: Gamepad 0,1,2,3. Does anyone know how to do this? Thanks!

Hi @Codeknight999!

Have you enabled gamepads in the projects settings?

You can check the example below on how it reads input from a gamepad.

Silly me, I forgot to turn the gamepad on. :man_facepalming: I tried out this code:

   var gamepads = navigator.getGamepads ? navigator.getGamepads() : [];
      var gamepad = gamepads[i];
 // Jumping (bottom button of right cluster)
            if (gamepad.buttons[0].pressed) {
                console.log('hello');
            }
           

but I am getting this error:Cannot read properties of null (reading ‘buttons’) for line 4. What am I doing wrong?

I am sorry in advance, I will probably reply in a few days as I will be out of town.

That sounds like there is no gamepad detected or something like that. I hope someone else has more knowledge about this.

It’s fine, I found a workaround. Thanks anyway!