How can I change a function for a specific ammount of time before putting it back ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By exciting_desk

I want to put my player in a “Slowed” state for like 3 seconds before giving him his original walking speed. I thought i could use a countdown with the Timer node but that didn’t really work out for me since i didnt know how to do it exactly.Thank you.

:bust_in_silhouette: Reply From: Ertain

Try this example inspired by the official documentation:

func slowdown():
     var previous_value = some_variable
     yield(get_tree().create_timer(1.0), "timeout")
     some_variable = previous_value

It worked ! Thanks a lot !

exciting_desk | 2021-02-22 07:44