|
|
|
|
Reply From: |
Socrates |
is_action_pressed
fires repeatedly as long as the button is pressed. If you want it to just fire once, you can use:
is_action_just_pressed
It’s actually not a button. I have a script tied to a generic node that handles all my input in an autoloaded scene so I can handle input in a scene-agnostic way. In that script, I handle all clicks and key presses with the _input(event) function.
Perhaps it would be easier if I shared the project, as it’s still quite small and should clarify things.
https://drive.google.com/open?id=1ZUbGzh_zIo1XJLreLgtXNDgoM3FsXFkF
If you wish to peruse the project, follow that link and click Hallowspire toward the top of the page, then download the folder.
Thanks in advance, sorry for the lack of clarity.
But yeah all events firing twice is making my click to move stuff difficult as well. The code triggers twice, so the sprite always moves twice as far in the direction of the click than intended.
Edit: actually, I’ve decided to ditch that approach and decentralize my input handling code. For some reason, if you do it the way I was doing it, events fire twice. I’m not sure why, but it’s not worth the hassle.
Daimoth | 2018-04-30 22:11
I have the same problem with my L2 (and presumably R2) buttons.
L2 and R2 are xbox-one controller trigger (variable) button types.
I gather my input in the _physics_process function.
I have a print line to debug which shows me the frame number:
print("get_tree().get_frame() = ", get_tree().get_frame()))
The other (not L2, R2) ‘buttons’ on the xbox controller do not have this issue so I think it is a problem when the variable-trigger type buttons only.
I get the input like this using the ‘Just Pressed’ variation as to prevent double input when holding the button down:
input_just_pressed[button_map.l2] = Input.is_action_just_pressed("ui_l2_" + str(input_controller))
When I press L2 once it registers twice in two different consecutive frames:
get_tree().get_frame() = 306
get_tree().get_frame() = 307
I will most likely have to add code to account for this ‘debounce’ input issue. Something along the line of keeping track of the delta for inputs as I do for input duration counts for other gameplay (holding buttons for x seconds etc).
Thanks,
Shaun
sjharb | 2021-05-29 17:41
Ok I found my issue. I am storing the inputs in an array:
input_just_pressed[button_map.l2]
But I was not collecting the input for certain open menu/hud selection conditions. By not collecting the input and updating my button press array, the value was still set to ‘true’ (i.e. pressed) for my input processing. So if anyone else is storing these input values they will want to be aware of such a coding mistake.
Thanks,
Shaun
sjharb | 2021-05-29 18:00