+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!


asked Jan 20, 2018 in Engine by Alex Night (17 points)
edited Jan 20, 2018 by eons

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...
answered Jan 20, 2018 by gonzo191 (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

answered Jan 20, 2018 by eons (7,786 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.