best way to assign player anims

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 3ngin33r8086

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?

:bust_in_silhouette: Reply From: markopolo

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 :frowning: