+1 vote

Hello guys!

im tryng to make a dash function:

func backdash():
    var can_dash = true
    var dash_time = 0
    if Input.is_action_pressed("BackDash"):
        if on_ground == true:
            dash_time += 1
        if direction == 1 and can_dash == true:
            if on_ground == true:
                can_dash = false
                velocity.x += -20
        if direction == 0:
            if on_ground == true:
                velocity.x += 20

the problem is:

the backdash last as long as been pressing the button..

i want to make it so it last only a few seconds, like castlevania games

sorry for my english!


in Engine by (17 points)
edited by

Edited to fix the code block.

2 Answers

+1 vote

I believe what you're looking for is Input.isactionjustpressed() instead of Input.isaction_pressed(). That is, assuming you're using v3.0 RC1.

if Input.is_action_just_pressed("BackDash"):
 # process backdash...
by (118 points)

im using 2.1

but i´m gonna keep it in mind when i use version 3.0!

thanks for your help! :)

+1 vote

Add a cooldown Timer to enable a variable that allows dashing, and start the timer when blocking the dash, I say a timer and not check dash animation because you may want to prevent instant continuous dash, but using an animation track to toggle a variable is fine too

by (7,796 points)

i forgot about the timers nodes!
thanks im gonna try this! :)

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.