Gamepads. Read the documentation but still have no clue.
I assumed it was something like
if(this.app.gamepad.isPressed(pc.PAD_1){
do.amazing.stuff('clearly not real code');
};
would do the trick as long as I knew the mapping of the gamepad, but I’m guessing there’s more to it than that. Was curious about people’s thoughts and solutions on this?
I’d like to get the analog sticks as well, but for now the simple dpad will do.
and it didn’t seem to work, I pressed every button on my controller to double check that the mapping wasn’t redirected incorrectly or something odd like that. Not sure what to do next and what do you mean by native GamePad API?
To be specific this is the controller i’m testing with.
It works fine with games on stream, but not sure if it will with web games.
So I found a gamepad, and it looks like this might be a bug in PlayCanvas.
What update is doing is it always update the current value, and sets the previous value to whatever was in current before it updated, so it’s always lagging one frame behind.
Now wasPressed returns true only if current says it’s pressed, and previous says it is not pressed. The problem seems to be that both current and previous always have the same value. If you print them out, they’re synced together, so the condition for wasPressed is never true.
My guess is that this is because previous and current are set to objects, and so they might both be pointing to the same object as opposed to making a copy.
I implemented my own version of update and wasPressed here as a proof of concept:
Please try this. It works for me. (Obviously this is only for one specific key but I thought I’d confirm if this does what you need before attempting to generalize it).
Yea I’ll test this! I’m sure it will work too looks like it.
So perhaps we should make this remark to the Playcanvas folk on fixing it. Because that seems like a lot of extra code to make an already functional code for other keys.
I have a workaround actually for this, but was curious to why it was so difficult to implement. Thanks
So it seems that just basic functionality for gamepads that I use to use for older versions of PlayCanvas don’t work any more. Or maybe I’m missing something
I get an error that takes me to ‘isPressed’ and says it’s null :S not sure what’s going on but thought I’d let you all know. Would be great to get this to work for my game project!
Also is there a way to let playcanvas know if there are gamepads at all?