Topic was automatically imported from the old Question2Answer platform.
Asked By
Lodea
I was trying to use the is_action_pressed function to set a variable to a certain value as long as the action is pressed.
Weirdly enough it seems that this works for the first second or so when the key is pressed, but then continues as if the key is no longer pressed.
func _input(event):
if event.is_action_pressed("snake_turn_clockwise",true): #<--- second parameter has to be true
turn_dir = 1
elif event.is_action_pressed("snake_turn_counterclockwise",true):
turn_dir = -1
else:
turn_dir = 0
Thank you very much. That seems to have solved that. Though I’m encountering a new problem now.
When I press the other key while the sprite rotates to change direction, sometimes the rotation hiccups and takes a fraction of a second before starting to rotate in the other direction.
Any Idea for what might be causing it and how to fix it?
Lodea | 2020-07-22 11:20
Maybe its because of the If … elif … else construction, where in theory a event can be dropped.
As long as i hold clockwise, counterclockwise events will be ignored. But its possible to press both in the same time.
Maybe this may help
func _input(event):
turn_dir = 0
if event.is_action_pressed("snake_turn_clockwise",true): #<--- second parameter has to be true
turn_dir += 1
if event.is_action_pressed("snake_turn_counterclockwise",true):
turn_dir += -1
klaas | 2020-07-23 09:31
Nope… Unfortunately, the issue persists
Lodea | 2020-07-23 10:25
There is a “gap” before echo happens …
check this out … works for me
Yup, works perfectly now. I still don’t understand why this solution works and the previous one doesn’t though.
Lodea | 2020-07-23 11:11
its simple.
When you type and hold a key in an editor the first letter appears immediately, than after some milliseconds the echo begins and the key gets repeatet. This prevents that whenever you type a key multiply characters appear.
This works because it checks the first key press and release of the key and dont rely on repetitive events.
klaas | 2020-07-23 18:49
Well, I’m not sure I completely get it yet, but it’s good enough for now. Thanks, you’ve helped me a lot