Topic was automatically imported from the old Question2Answer platform.
Asked By
Max_EinDax
Im working on a roll movement action with the help of an youtube tutorial series.
But im wondering how i can add a 3 seconds wait time in between the rolls.
This is the code so far: func move_state(delta): if Input.is_action_just_pressed("roll"): state = ROLL func roll_state(delta): velocity = roll_vector * ROLL_SPEED animationState.travel("roll") move()
Depends on how you’d like to implement this ~ here are a couple options:
Extending the animation time and setting the Transition property (within the AnimationTree) to AtEnd
Using a simple timer.
The easiest option for setting a one_time timer is using yield(get_tree().create_timer(3), "timeout") ~ this will pause the code execution of the function until the timer finishes
e.g.
var just_rolled = false
func move_state(delta):
if Input.is_action_just_pressed("roll") and not just_rolled:
state = ROLL
just_rolled = true
yield(get_tree().create_timer(3), "timeout")
just_rolled = false
edit:
This example uses syntax for Godot 3.x.x, in Godot 4 yield is now using the await keyword. I’m not familiar with it yet, so once you find the correct way please add a comment or answer with the right syntax for anyone else finding this issue.
Thanks for the detailed help. The code works exactly like i needed it. Heres the 4.0 syntax:
var just_rolled = false
if Input.is_action_just_pressed("roll") and not just_rolled:
state = ROLL
just_rolled = true
await get_tree().create_timer(3).timeout
just_rolled = false