create a wait pause function between 2 different animations

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

i have this beatem up script here:

so, when the player is using the punch attack, and when he finishes the punch before changing to another animation i want a slight pause between the change of animation. if you look at my gif .

the sprite is punching while trying to walk at the same time. how do i add wait time or timer function after the punch action is stpped ?

:bust_in_silhouette: Reply From: Inces

Most elegant sollution would be to design minimalistic state machine, one of states being “pause”, preventing player from reacting to inputs.
You can make an array of all animations You want to shortly freeze player after they are finished, let’s call it freezinganims. Add timer to the tree, lets call it cooldowner and connect its timeout to the main script. With this, connect “animation_finished” of animation player to your main script, and use this signal to trigger timer

func on_animation_finished(animation):
         if  freezinganims.has(animation):
              $cooldowner.start()
              state = "paused"

func on_cooldowner_timeout():
         state = "normal"

and of course, in your input code, state paused is supposed to rpevent reaction :

func input(event):
       if state == "paused":
             return