Best Practices for 2D Animation with Independent Sub-Animations

Godot Version4.2


So, I’m doing 2D animation with node-based sprites. I would like to be able to do things like have the character running in a direction, but looking in another - but I don’t want the head motion constrained so they can’t look in full 180 like they’re possed. Likewise, I’d like to be able to blend animations together, such as have all my various upper body action animations like jab, cross, sword swipe, throw weapon, etc., being independent of the lower body so I can have characters do these things while standing, running, jumping, sliding, etc.

I’ve tried hardcoding these things before, and it works okay, but not being able to preview things in an editor ends up taking too much time to be a reasonable workflow.

Is this what the animation tree is four? And if so, how do I use it for this purpose?

First it should go without saying that you need to isolate the head sprite and lower body form the upper body. This should be straight forward if you know how to make your sprites.

You can sort your nodes above or below the other node so that what sprite needs to be on top is on top. If you still need more sorting options look for Z Index under ordering in the inspector with your node selected. You can even change the z index in the animationplayer node if you want to change the layers depending on where the character is facing.

The animation tree node just saves a lot of coding, you can accomplish more or less the same thing by making your own state machine. But I do recommend using the animationtree node as it saves a lot of code. Here is a tutorial I just looked up. If that one doesn’t work for you, there are plenty more on YouTube

Personally I would isolate the head, body and legs into their own separate state machine/animationtree so you can have full control of what animation plays when.

Thanks for the video, it was helpful to see how direction blending is used using the Tree.

I’ve been experimenting with the animation system, and, a couple thoughts:
I had been thinking of laying out my sprite sheet to do frames along one axis, and direction along the other. Since AnimationPlayer can only edit FrameCoord as a vector, it doesn’t seem like AnimationTree would be able to mix separate animations for each axis (animation frame vs direction) together, which is a drag. Is there any work around for this, or am I stuck hand futzing with each animation in each direction by hand?

Blending seems to work mostly by doing a weighted average on the property values. Is there any option to do other operations on values, like additions, or max(), that sort of thing?