Loop an animation for a specified amount of time - timed state machine?

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

I am designing an enemy which will charge to attack. The animation tree used is as follows: [charge-start]->[charging]-[charge-end]. I have an animation for each of these states.

I would like to loop the [charging] state for a specified amount of time, because the enemy can charge for a different amout of time based on the game. However, I cannot find a way to implement this using AnimationPlayer or AnimationTree or BlendTree. So far, the only solution I could think of is to use a timer within the code, but I am hoping to avoid this because it feels unneccessary and can cause bugs if not careful.

IMHO a timer is the way to go. Keep it simple.

SteveSmith | 2023-02-06 13:59

:bust_in_silhouette: Reply From: Guliver_Jham

Yeah, a timer within the code is the way to go, i’d use the physics_process delta wich returns its value in seconds to add to the timer.

Bonus → if you don’t know, this button makes the animation play until you stop it.