Skip to content

fix: ensure all units in attack groups engage enemies#1374

Merged
braedonsaunders merged 1 commit into
mainfrom
claude/fix-ai-unit-engagement-M2jVZ
Feb 4, 2026
Merged

fix: ensure all units in attack groups engage enemies#1374
braedonsaunders merged 1 commit into
mainfrom
claude/fix-ai-unit-engagement-M2jVZ

Conversation

@braedonsaunders

Copy link
Copy Markdown
Owner

Previously, when AI issued attack commands to groups of units:

  1. Only front-line units would engage - back units stayed idle
  2. Back units drifted backwards away from combat

Root causes:

  • CombatSystem skipped target acquisition for units not in "hot cells"
  • FlockingBehavior caused idle units to yield to moving units
  • Back units had no cohesion pulling them toward the fight

This fix adds a hasActiveAttackCommand flag to track units that are advancing toward combat. These units now:

  • Always search for targets at sight range (not throttled)
  • Don't yield to physics push from other moving units
  • Have cohesion toward engaging allies
  • Use combat-level separation to stay grouped

Changes:

  • SpatialGrid: Add hasActiveAttackCommand to inline entity data
  • MovementOrchestrator: Pass hasActiveAttackCommand to spatial grid
  • CombatSystem: Attack-moving units use aggressive target acquisition
  • FlockingBehavior: Units with attack commands don't yield, cohere toward allies, and use tight separation

https://claude.ai/code/session_01MAHtq37jrekhgXFQT7H1Vh

Previously, when AI issued attack commands to groups of units:
1. Only front-line units would engage - back units stayed idle
2. Back units drifted backwards away from combat

Root causes:
- CombatSystem skipped target acquisition for units not in "hot cells"
- FlockingBehavior caused idle units to yield to moving units
- Back units had no cohesion pulling them toward the fight

This fix adds a hasActiveAttackCommand flag to track units that are
advancing toward combat. These units now:
- Always search for targets at sight range (not throttled)
- Don't yield to physics push from other moving units
- Have cohesion toward engaging allies
- Use combat-level separation to stay grouped

Changes:
- SpatialGrid: Add hasActiveAttackCommand to inline entity data
- MovementOrchestrator: Pass hasActiveAttackCommand to spatial grid
- CombatSystem: Attack-moving units use aggressive target acquisition
- FlockingBehavior: Units with attack commands don't yield, cohere
  toward allies, and use tight separation

https://claude.ai/code/session_01MAHtq37jrekhgXFQT7H1Vh
@braedonsaunders braedonsaunders merged commit 665ad95 into main Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants