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 (373 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 (750 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 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.