Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | batomow |
I was having some Input detection problems and as usual i checked to see if i could find a solved question. Many people appear to have the same problem. Pressing a key, then while this said key is pressed, pressing another key and then releasing the originally pressed key. Most solved questions point out that the _input() function only detects the last event and that the _process() function should be used instead.
Well in my case i’m using _process() and defined in my project’s input map an action called “movement” and two more actions called “left” and “right”. The code looks something like this:
func _process(delta):
if(Input.is_action_pressed("movement")):
direction.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"));
#more validation code
It appears that if press the pattern i described before (Right then Left and release Right while keeping Left pressed and then release Left) and print out the values detected, the debug shows:
L: 0 R: 1
…
L: 1 R: 1
…
L: 0 R: 0
What fixed it in the end was to get rid of the “movement” action and thus the code to this:
func _process(delta):
if(Input.is_action_pressed("right") || Input.is_action_pressed("left")):
direction.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"));
#use direction for something
I don’t get why it worked. Is there something special about the way Godot handles input? Should i add the issue to the repository?
- Movement was mapped to WASDQE. Left and right where mapped to A and D respectively.