The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I'm trying to have a character do a dash move by pressing twice in directional pad (so I guess a "press, release, press" logic), but cannot seem to have the logic right.

I have some code like this:

func _process(delta):

    var move_right = Input.is_action_pressed("move_right")

    // here I tried some logic to detect player pressed twice in the directional pad
    (...)

    if(dash):
         // do dash move
    elif(move_right):
        player.set_scale( Vector2(1, 1) )
        player.move_local_x( player_speed * delta )

I tried using is_echo() in the _input()
Also using is_action_released()
Also tried storing the previous action press (or previous action release) in a variable.
Just can't seem to get it right.

It either did not work or the character would just dash by holding directional pad right.

in Engine by (388 points)
edited by

1 Answer

0 votes
Best answer

This is not a Godot specific question, but one which can be applied to any tech.
I'll answer anyway.

  1. Declare a timer variable with a value, may be 0.5
  2. In the process function, you should reduce it by delta
  3. Reset the timer to 0.5 on key press and also if is_echo is false.
  4. Then check if the timer is greater than zero when the key is pressed

That should do it

by (751 points)
selected by

Thanks for the help!

An alternative way would be to store the current time and compare to the last, so you dont need to put anything in _process().

Another option would be to use a Timer node + timeout signal

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 Frequently asked questions and 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 [email protected] with your username.