Teaching Soldiers to Fight: AI First Steps
This week the army finally started acting like one. Until now, soldiers were glorified turrets with legs — they attacked whatever was closest and happily pathed through hazards to do it.
The behavior tree
Every soldier now runs a small behavior tree, evaluated a few times per second:
- Survive — retreat to the nearest tower’s healing aura when below 25% HP
- Protect — intercept orcs targeting the hero or a building
- Fight — engage the highest-threat orc in range
- Regroup — return to the rally point when idle
The ordering matters: a soldier mid-fight will still peel off to body-block an orc charging your barracks.
Pathfinding on the build grid
Because players reshape the map with walls in real time, we re-run flow-field pathfinding whenever the grid changes. Flow fields turned out to be a great fit — one field serves hundreds of units, so big armies stay cheap.
Next up
Formations. Right now twenty soldiers form what can only be described as a “friendly mob”. We want lines, wedges, and tower garrisons — that’s the next sprint.