0 votes

Hi everyone,

I've been working on my own game for quite some time with many restarts to get to know the engine. I think I figured out many great things about Godot, but one was always a bit of an eyesore to me.
When I first tried to add animations to my game I used an Animation player which worked fine. When I moved to a top-down approach like Secret of Mana I started using an AnimationTree with a state machine and sub state machines instead to make implementing view directions with my sprite easier.
As one example, I have a move state but inside it there is a walk and a run state. This works fine, but now I wanted to code more complex behavior like attacks.
Because of the bigger complexity I added a coded state machine to my project, which is called during the _process() step, but now I see that I am effectively re-implementing the state machine I create within my AnimationTree with my own coded solution.
I have seen guides on how to implement your own state machine or how to use an AnimationTree but not both combined.
Therefore I ask whether there are any best practices on this topic.
I know there may not be a best solution on this, but any idea is appreciated.

Godot version 4.0.beta6
in Engine by (185 points)

1 Answer

+1 vote

What I've done is try to have one animation for each state. So if the character has a "walk" state, that will have an accompanying "walk" animation. If a group of animations are a part of a mechanic, I try to have those put together in one of the nodes of an AnimationTree, and have the state control that group. I use a decent number of signals to keep these synchronized, where the AnimationTree may have a script which checks for a certain state, and then handles the animation (or its properties) related to that state.

Hope this helps.

by (3,144 points)

Yeah, that sounds like what I am currently doing. I normally try to not implement the same ideas in two places (AnimationTree and code here), but it seems that it is impossible here. The one thing I find most exhausting is the need to implement the edges according to my states and animations in the AnimationTree. Do you just replicate the state machines structure in the AnimationTree as well?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.