[SOLVED] How to use ‘wasReleased’ with gamepads

hey @yaustar it still doesn’t work?
can you take another look over my code and see if there is anything wrong.
also like I said before everything works fine with the controller except this.

It’s right here https://playcanvas.com/editor/code/719734?tabs=36884907

@yaustar the error came back

[Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10]: Uncaught TypeError: this.app.gamepads.wasReleased is not a function

Hi @WilliamBoersma31,

I gave lvl11 a try and it works quite ok, I can move around without getting any error.


if you beat a level then the game crash’s

[Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10]: this.app.gamepads.wasReleased is not a function

TypeError: this.app.gamepads.wasReleased is not a function
at scriptType.P2Lauch.update (https://launch.playcanvas.com/api/assets/files/Launch.js?id=36884907&branchId=b54e717d-51a8-41a2-8464-cdf777c7a322:10:29)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:59992:19)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:60040:11)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:60606:49)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:60623:9)
at Function._helper (https://code.playcanvas.com/playcanvas-stable.dbg.js:41012:12)
at Function.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:41027:9)
at Application.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:66807:20)
at https://code.playcanvas.com/playcanvas-stable.dbg.js:67488:16

There is another forum topic about this problem. I wonder if anything has changed since then.


Hi @Albertos I tried using that topic’s solution and it did nothing.

If there is still no working wasReleased function for gamepads I think you can do something like below.

var pressed = false;
if (pressed && !this.app.keyboard.isPressed(pc.KEY_0)) {
    pressed = false;
    // Your wasReleased functions here

else if (this.app.keyboard.isPressed(pc.KEY_0)) {
    pressed = true;
    // Normal isPressed functions here

@Albertos how do I call pressed would it be

if (pressed) {
‘my code’


if (pressed) {


else {
‘my code’

Hi @WilliamBoersma31,

You can check the following example on how it reads input from a gamepad:

Hey @Leonidas I have controller support working well I just need a way for wasReleased because of the way one of the abilities works. You guys should really add wasReleased for gamepads it would save me a lot of headaches.

That indeed would be useful, make sure to log it here if you are able

In the meantime @Albertos 's suggestion can easily add the same behavior for you.

Oh, my bad. I thought we were talking about wasPressed :man_facepalming:

Yep, we don’t have wasReleased function in the API.

1 Like

Now I get confused. What is the difference between wasPressed and wasReleased?

was pressed is a tap of a key was released check when you let go of the button.

I had to do some extra research because the API description of wasPressed in the user manual confused me. You can find a better description of these APIs on the page below. For the wasReleased function you can use my solution above. You can just add the code to your update function and only have to adjust the key if necessary. Don’t forget to add the variable to the beginning of your script.


@Albertos I tried your code above and it didn’t work.
Here is my code if you want to take a look

Hi @WilliamBoersma31! Your setup is not the same as my example. You have to add your code for the wasReleased function on the right place. Also the initialize of the boolean presssed has to be on top of the script and not in the update function, otherwise this boolean is always false.

what is the right place?