I’m currently trying to make a frog enemy for my 2D platformer. It has a hopping animation that includes a windup and landing. I want to only make it move during the hopping part of the animation, and make it stop during the windup and landing. The problem is I’m using an animation tree, and haven’t been able to figure out how (or if it’s even possible) to get data on the currently playing animation, such as its current progress. I could just use a timer or something to space out the movement intervals independently of the animation, but that feels messy and like it’ll be prone to becoming out of sync. Is there a way to get the progress of the currently playing animation from the animation tree?
Hello!
If you have an AnimationTree in your SceneTree, this means you have access to the animation_started() signal.
If your code can hook up with the signal, then you can check the name of the animation that was started.
You can make a match-statement for specific animations to look out for.
Then check for the linked AnimationPlayer’s current_animation_position variable value…
Wait a moment, now that I think about it, your hopping animation must be an animation of the AnimationPlayer that’s hooked to the AnimationTree, right?
Why don’t you add a track to it of type “Call Method”.
At the point of windup and landing, call a method (maybe restrict_movement)
which basically enables and disables a boolean.
In your process function, you can then make a condition to only allow movement based on the value of the boolean.
I actually figured out a different way to do it that I think works well for my project. Basically I set an exported int called something like “animation_velocity” and used the hop animation to directly manipulate it so that I could set the value to whatever I wanted for each frame. Then I just set the enemy’s velocity.x value equal to the animation_velocity value whenever it’s in its hop state.