lrdprdx wrote: ↑Sat Mar 22, 2025 5:57 am
How the system knows what animation it should set ?
Can you think of a single animation system that will work for all animated entities in your game? How should the animation component used by that system be structured so that it can be used on all animated entities?
An entity in ECS is just an identifier. A component is a modular piece of data that gives meaning to that entity.
In many examples around the web you see people using a "position" component, usually a table with "x" and "y" properties, as opposed to having individual "position_x" and "position_y" components. In the same way, the animation component can have one or more properties as well.
How to design the components and their properties is up to you (like what to group together as properties of the same component vs. what to separate into different components), but from this article here:
https://joshmccord.dev/blog/sprite-animation-ecs/
...it's within standard to have a complex "animation" component that has many properties that describe the animation that the entity is performing.
The animation system then processes that animation component to update it, and this system doesn't affect the behavior of the entity.
Each behavior system (like you're doing right now with separate fly, walk etc systems) will monitor the context of the game (input, physics, AI and other game events) and react to these events, such as changing one or more properties of the animation component of the entity (or changing nothing, letting it continue on as it is).
So the animation system worries about performing the animation based on the properties of the animation component (modifying some of those properties), while the behavior systems change some properties of that animation component as well, but with the intent of preparing an animation to be performed.
So to answer your question, the fly behavior system already knows the possible animations that the animation component can be set with, as the entity with the fly tag is either flying or touching something right now, after which the fly system will remove the fly tag from the entity and apply another behavior tag to it so that another behavior system can pick up from there.
By the way, the entity doesn't have to go from a flying tag to another tag directly. You can have a
transition tag whose system sets up animations etc, like a fly-to-idle tag component when the character lands after flying. After it's done, the fly-to-land system tags the entity with the actual "idle" component.