Skip to content

fix: improve AI unit engagement and combat behavior#1369

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

fix: improve AI unit engagement and combat behavior#1369
braedonsaunders merged 1 commit into
mainfrom
claude/fix-ai-unit-engagement-f6VOQ

Conversation

@braedonsaunders

Copy link
Copy Markdown
Owner

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

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
@braedonsaunders braedonsaunders merged commit 5692f03 into main Feb 4, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +241 to +245
// 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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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