Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | roxasthewise | |
Old Version | Published before Godot 3 was released. |
Can godot know if there is no input detected?
I have player state, and i want to go to idlestate if player’s giving no input to the game.
How do i do that?
How do you detect your input? You could just check if none of your inputs are being pressed.
timoschwarzer | 2016-11-25 13:02
yeah i did try using (!event.is_action_pressed(“action”)) for all d-pad input, but it bugs my player movement.
roxasthewise | 2016-11-25 13:28
If your input handling is a series of if inputXXX: YYY
, then you can set a boolean inside them to true
and test if the boolean is false
at the end, then you can handle the case where no input was given.
Testing if there is no input doesn’t make sense on its own, IMO. Your game reacts to input, so you should be able to check your own logic variables and do something in consequence (and if you don’t have some, create them, the boolean I mentionned above could be one, but I’m sure you have something like “direction”, “is jumping” or whatever your game does).
Zylann | 2016-11-25 13:39
it’s all ok. until i put
if(!ev.is_action_pressed("move_up") && \
!ev.is_action_pressed("move_down") && \
!ev.is_action_pressed("move_right") && \
!ev.is_action_pressed("move_left")):
exit(player.idleState)
and the movement starts to bug, like some action is missmatched
roxasthewise | 2016-11-25 13:48
Where did you put this? In which function?
Zylann | 2016-11-25 13:52
in func input(ev):
roxasthewise | 2016-11-25 13:57
If you use _input
, then testing if there is no input is actually up to you.
As I said:
Testing if there is no input doesn’t make sense on its own, IMO. Your game reacts to input by setting some variables and calling functions, so you should be able to check your own logic variables and do something in consequence (and if you don’t have some, create them, the boolean I mentionned above could be one, but I’m sure you have something like “direction”, “is jumping” or “is moving” or whatever your game does).
As an example, considering only one input:
func _fixed_process(delta):
if moving_left:
move_local_x(-speed * delta)
# Moving every frame
else:
# Not moving, we are idle here (but called every frame so be careful)
func _input(event):
if event.is_action_pressed("left"):
moving_left = true
# We are going to move now, begin animation
elif event.is_action_released("left"):
moving_left = false
# We are idle now (called only once because we are in _input)
Note that you are not forced to do the idle animation directly in _input
or _fixed_process
, these are just starting points, especially if you have more than just one input.
Zylann | 2016-11-25 14:08
yeah, i’m changing my input handling in _fixed_process
instead _input
now. less work there…
roxasthewise | 2016-11-25 15:14