0 votes

What's the best way to assign animations for a player? I'm using an AnimatedSprite. what I'm doing now is making a func called assign_anim() and calling animations based on a certain event or events, but organizing all the elifs so it all works is very annoying. I also used to just call the animations while checking for input like running and jumping, and that worked, until I started doing animations that needed to be called while other animations were being called and it all kind of fell apart. how does everyone else here do it?

in Engine by (18 points)

1 Answer

0 votes

For complicated entities with lots of animations I end up using what amounts to nested state machines (sort of a poor man's behavior tree), and each frame the entity script checks the status of those state machines and updates the animation if necessary.

On my player sprite, for example, I have a top level state machine for whether the player is running, idle, or in the air. There's another state machine just for airborne states: pushing off, ascending, at the apex, descending, landing. This way, if the player runs off an edge without jumping, for example, the player script logic can realize that and the animation can go from running to airborne_descending smoothly.

There are a lot of conditionals, though - I've got no silver bullets for making convoluted logic go away :(

by (629 points)
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 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 webmaster@godotengine.org with your username.