Godot Player Movement problem

Hi guys,
I am following the Godot 2D course. In the second block. The Alien Attack. I do understand the script for the player Movement but, in my game, when the key is pressed the player only moves one step and stop. I have to press several times for a small movement. I left the keyboard Key pressed the player do not keep moving. My script looks the same as the one in the course but doesn’t seem to work.
I am sharing a screenshot of the script.

In addition of what I explained before… I can make the player move if I comment line Nº 4 but then, once the player start moving, I can’t make it stop…
What can I do?
Thanks in advance for your help!

hi Antonio,

you have a slightly different line for checking the Inputs.

for the Input and listening for keypresses there are a couple of different things we can look for.

Input.is_action_pressed()
this one is the one we need her as this will constantly return true for every frame the button is held down.

Input.is_action_just_pressed()
this one however, will only return true when the button is initially pressed.
as you have found out there, when you release the button and press again, it only runs once.

if you change those lines to use is_action_pressed, that should get you back on track hopefully.

Darren

Thank you so much!
How silly I am

Not at all, it’s an easy one to miss and I’ve done it countless times before using the autocomplete and didn’t notice.
And sometimes just need a second pair of eyes to look over it.

On a positive tho, you now know how it behaves and what to look for if you ever have a similar behaviour in future :wink:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms