Animation interrupted by another one

Godot Version

Godot 4.3

Question

Ask your question here! Try to give as many details as possible
Hi everyone,
i am making a 2d platformer; while playing an animation (“attack”) it run another animation (“idle”) without fully run the previous animation…Mmmm, i thougth a way so solve this probblem is defining come flag variable to indicate wn animation is already running…what do you think about ?

No need to define a flag. The animation can tell you when it’s finished.

There’s also a is_playing() function if you want to check right away if an animation is playing.

ok, considering I defined this to play the several animations:
var animation_player: AnimationPlayer
Could I check if no one animation is being played?? :no_mouth:

Yes, as @paintsimmon mentioned you can use is_playing:

if not animation_player.is_playing():
  # do-stuff

Or you use current_animation to get the currently playing animation (it’s "" when none is playing). Or you connect/await the animation_finished signal as @TokyoFunkScene suggested and start the next animation when the previous is finished.
Or you use queue to queue the next animation.

I suggest you take a look at the documentation, all properties, methods and signals are listed and explained there: AnimationPlayer — Godot Engine (stable) documentation in English

There you will probably find what fits your use-case best :).

use an AnimationTree.
you can use expressions to make things easier, they will read variables in one of your files, so you don’t have to get the AnimationTree to change values manually all the time.
here’s a tutorial on expressions while they update the docs:
https://godotforums.org/d/39521-this-is-how-to-use-animationtree-state-machine-transitions-with-expressions

do not use an AnimationPlayer on its own unless it’s for something very simple, and in that case an AnimatedSprite would be better.
explosions, single looped animations = AnimatedSprite
characters, enemies, a chest, a door = AnimationPlayer with AnimationTree

Your other question was about setting up collisions? and I told you to use a state machine?
well with an AnimationTree you could define in what order you want the animations to run, or if an animation must not transition at all, like a death animation.

idle -> hurt -> death
idle -> electricity -> death

you can also make them go back when a condition is met, like with walking:

idle -> walk
walk -> idle

an AnimationTree will also ensure that an animation finishes playing before going into the next one, and you can set it to smoothly transition, blending frames from one with the next.

1 Like