[SOLVED] How to use ‘wasReleased’ with gamepads

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.

https://developer.playcanvas.com/en/tutorials/keyboard-input/

@Albertos I tried your code above and it didn’t work.
Here is my code if you want to take a look
https://playcanvas.com/editor/code/719734?tabs=39592820,36884907

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?

There.

now its only doing the

Is this line correct?

this.app.keyboard.isPressed(pc.PAD_1, pc.PAD_FACE_1)

no thanks for pointing it out

still didn’t work

For me your code is a bit too chaotic to be able to see what is going wrong. What is the result so far and how did you expect the result to be?

it is supposed stop your momentum when you tap and if you are pressing a direction when you release you fly really fast in that direction

whats happening is I cant move at all

I would start to check if your wasReleased function is executed correctly.
Add console.log("was released"); to the same place as your wasReleased code and check in the console of your browser if you get this log on the right momemt.

its not activating at all also its also not doing the normal isPressed my controller just disconnected

I don’t have a controller, so I can’t help you with that.