0 votes

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?

in Engine by (26 points)

How do you detect your input? You could just check if none of your inputs are being pressed.

yeah i did try using (!event.isactionpressed("action")) for all d-pad input, but it bugs my player movement.

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).

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

Where did you put this? In which function?

in func input(ev):

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.

yeah, i'm changing my input handling in _fixed_process instead _input now. less work there..

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.