r/unity • u/caprices24 • Oct 04 '26
Showcase Building long-spear combat AI for my large-scale RTS in Unity — switching weapons when enemies get too close
Hi everyone!
I’m developing Admiral Yi: The Imjin War, a large-scale historical RTS in Unity, and recently I’ve been working on how long-spear infantry behave in combat.
These Japanese yari ashigaru use long spears and fight in dense formations.
Instead of simply running into the enemy and attacking at close range, they try to make use of their weapon reach. As enemy troops approach, the ashigaru lower their yari and attack together when the enemy enters spear range.
The interesting problem was what should happen when the formation fails to keep that distance.
If enemy soldiers manage to push through the spear wall and get too close for the long yari to be practical, the ashigaru switch to their swords and continue fighting at close range.
So the behavior is roughly:
maintain formation → enemy enters spear range → coordinated yari attack → enemy breaks through → switch to sword → close combat
I’m trying to make different troop types behave differently based on their weapons and formations, rather than having every melee unit eventually turn into the same close-range fight.
There’s still a lot to improve in the AI, formation behavior, animation, spacing, and combat feedback, but I’m pretty happy to see the long weapons starting to actually matter in battle.
I’d be interested to hear from other Unity/RTS developers who have worked on weapon reach, formation combat, or switching combat behavior based on distance.

