Godot Version
4
Question
I am new to GDscript and I am trying to make a dash function in my 2d platformer game without reference to tutorials. I am having a problem getting my dash to run for more than a millisecond. Here is my code:
if Input.is_action_just_pressed(“dash”):
if direction:
velocity.x = direction * SPEED * 2
animated_sprite.play(“dash”)
await get_tree().create_timer(1.0).timeout
else:
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
Is this called in the process-function? Dont use Await inside of process functions as it gets called 60 times per second, so lets say in frame 1 you press the dash button → your dash gets executed, but frame 2 dash is no longer pressed → your other code gets executed since await doesnt stop the second run of this function to stop. A way to fix this would be to add a variable called “dashing”. Set the dashing variable to true when dash is pressed and a timer and connect the timeout signal to a function that sets the dash to false. In your process function you skip the else-part if “dashing” is set to true → change “else:” to “elif dashing not true:”