Frontline Command | Dev Log #2
Frontline Command (Dev Log #2) (Publish)
Following up from Dev Log #1, here’s a rough diagram of how my scripts were interacting initially. The circular dependency between FormationManager -> FormationUnit -> FormationManager was a major pain point, it’s tightly coupled, extremely hard to extend, and a nightmare to maintain.
With this setup, introducing UnitState was nearly impossible without breaking something else.
After multiple revisions and some serious refactoring, I finally managed to add UnitState and restructure the system.
In this new design, I introduced a SwarmService to manage a higher-level abstraction for controlling groups of units. It also assigns and manages the roles each unit should take. For instance, a LeaderFormationRole sits at the center of the formation and updates group-wide context attributes like path, velocity, forward direction, and center position. These attributes are crucial because other swarm units (UnitFormationRole) rely on the FormationContext to decide where to navigate at each node.
UnitFormationRole handles how individual units move in sync with the leader while performing local obstacle avoidance. Each unit casts lines around itself to detect nearby obstacles and steers away to avoid getting stuck. Overall, I’m really happy with how this feels in practice.
This update also adds path smoothing for better movement around obstacles. It’s not perfect, sometimes curves a bit too sharply but the result is a noticeable improvement.
On top of that, when a unit is in Unit.Idling, it now scans for nearby enemies and triggers Unit.Attacking if one is detected. In UnitCombat.cs, the unit rotates toward the enemy when attacking:
This will probably be my last dev log for a while, as I’m shifting focus to preparing for technical interviews and working on a smaller side project.