fix: improve AI unit engagement and combat behavior#1369
Conversation
This commit addresses multiple issues with AI unit combat behavior: 1. Move command override fix (AIMicroSystem): - Removed 'moving' state from canProcessUnit condition - Units given a pure move command no longer stop to attack - Matches SC2 behavior where move commands ignore enemies 2. Combat zone awareness (CombatSystem): - Added tracking for units near friendly combat - Idle units within sight range of attacking allies now engage - Uses sight-range search instead of attack-range for these units - Enables SC2-style "join nearby combat" behavior 3. Flocking behavior fixes (FlockingBehavior): - Reduced separation for idle units near combat (prevents spreading) - Enabled cohesion toward attacking allies for idle units - Reduced push priority so back units don't drift away - Added isNearFriendlyCombat flag to Unit component These changes ensure all units engage in combat like SC2: - Front units fight while back units move into range - No more idle units drifting backwards during battle - Pure move commands work without auto-attack interruption https://claude.ai/code/session_01DhMDGUgzVt9eFmdJyn8MTB
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df60a4e13e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Now, for each idle unit, check if friendly units are fighting nearby | ||
| for (const entity of units) { | ||
| const unit = entity.get<Unit>('Unit'); | ||
| const health = entity.get<Health>('Health'); | ||
| const selectable = entity.get<Selectable>('Selectable'); |
There was a problem hiding this comment.
Restrict near-combat marking to idle units
The loop is labeled “for each idle unit,” but there’s no state filter here, so moving/attackmoving units are also marked isNearFriendlyCombat. That flag is later used by FlockingBehavior to change cohesion/priority, which can pull pure move-command units toward nearby combat even though the commit’s goal is to keep move commands from being influenced by enemies. This only happens when a moving unit is within friendly-attacker sight range, but it reintroduces combat drift for those move commands. Consider gating this block with unit.state === 'idle' (or whatever states you intend to be affected).
Useful? React with 👍 / 👎.
This commit addresses multiple issues with AI unit combat behavior:
Move command override fix (AIMicroSystem):
Combat zone awareness (CombatSystem):
Flocking behavior fixes (FlockingBehavior):
These changes ensure all units engage in combat like SC2:
https://claude.ai/code/session_01DhMDGUgzVt9eFmdJyn8MTB