Guide

Game companion AI design explained

Harbor Ruins shipped with two story-critical companions: a scholar who unlocked lore gates and a scout who tagged weak points on elite enemies. Telemetry from the first closed beta was brutal: 41% of player deaths occurred in rooms where a companion had wedged the player against a doorway, 23% of boss attempts failed because the scout charged the arena alone and died off-screen, and support tickets repeatedly asked for a “dismiss companion” toggle. The characters were well written; the companion AI was not. Companions sit in a uniquely hostile design space. They must feel like allies with personality, not escort mission baggage, yet they share the player’s navmesh, camera, and combat readability. Too passive and they are wallpaper; too aggressive and they steal agency, kills, and resources. This guide maps companion archetypes, the autonomy-vs-control spectrum, follow and formation behavior, combat assist priorities, bark and context systems, failure recovery, a Harbor Ruins refactor walkthrough, an architecture decision table, pitfalls, and a production checklist. For enemy patrol AI, see behavior trees; for invisible pacing orchestration, see the AI director guide.

Companion archetypes and player expectations

Before writing code, classify what job the companion performs. Each archetype implies different autonomy defaults and failure tolerance:

  • Escort NPC — must survive to progress; low combat skill, high pathing reliability, obvious “wait here” affordances.
  • Party combatant — contributes DPS or healing; players expect competent targeting but not kill-stealing.
  • Utility pet or drone — fetch, scan, torch-light; minimal combat; players forgive odd movement if utility is crisp.
  • Narrative witness — reacts to world events with barks and animations; may be invulnerable; AI is mostly positioning and triggers.
  • Player-directed summon — short-lived; high obedience; telegraphed lifetime and cooldown are part of the design.

Mixing archetypes without signaling creates confusion. If the scholar is narrative-only, do not let them wander into spike traps. If the scout is a combatant, give them telegraphed ability cooldowns players can read. Document the archetype in your design brief; it drives every downstream tuning knob.

The autonomy spectrum

Companion AI is a slider from fully scripted to fully autonomous:

  1. Rail-locked — follows spline or trigger volumes; used in set-piece corridors.
  2. Follow with leash — navmesh path to anchor behind player; teleport catch-up beyond distance D.
  3. Squad tactics — chooses cover, flanks, and abilities from a priority list keyed to player stance.
  4. Full autonomy — utility AI or GOAP plans multi-step goals; rare for always-on companions because debugging cost is high.

Most shipped games land on follow-with-leash for exploration and squad tactics for combat, switching modes at encounter boundaries. Explicit mode transitions prevent the scout from pathing through a cutscene trigger while the player is in a menu.

Follow behavior, formations and navmesh etiquette

Bad follow AI is the top companion complaint in playtests. Implement these patterns before polishing combat:

Anchor and slot system

Assign each companion a formation slot relative to the player: back-left, back-right, flank. Slots rotate when the player turns sharply so companions do not cross through the camera. Recompute slot world positions every 0.2–0.5 s, not every frame, to reduce oscillation. When a slot is blocked, fall back to nearest reachable point within a tolerance radius rather than hugging the player’s capsule.

Navmesh and doorway rules

  • Thin doorway policy — companions yield: if player capsule overlaps doorway trigger, companions pause outside until clear.
  • Stuck detection — if path progress < 0.5 m over 2 s, teleport to slot behind player (with fade VFX, not pop).
  • Elevator and ladder contracts — companions snap to player floor on vertical transitions; never path mid-air.
  • Destructible and dynamic obstacles — refresh navmesh or use local avoidance rings; see level streaming when companions cross cell boundaries.

Leash, catch-up and separation

Define three distances: comfort (3–6 m behind), warn (jog animation, bark “wait up”), and teleport (10–15 m, or off-camera > 3 s). Scale distances per movement mode — sprinting players need larger comfort radii. In multiplayer, companions are usually client-local or server-owned pawns replicated to all clients; authority rules must match your netcode model so followers do not rubber-band across the party.

Combat assist: targeting, abilities and aggro

Combat companions fail when they compete with the player instead of complementing them. Structure assist as priority stacks evaluated each tick or on event:

  1. Revive or stabilize downed player (highest).
  2. Interrupt enemy channel or heal (elite telegraph window).
  3. Apply debuff the player recently tagged (weak-point sync).
  4. Finish low-HP trash below 15% if player has not attacked 2 s.
  5. Damage nearest threat to player.

Target selection should bias toward enemies the player damaged in the last 3 s (assist credit) and away from enemies the player is actively meleeing (avoid knockback clashes). Cap companion DPS to 25–40% of player output in RPGs so progression stays player-centric. For healing companions, overheal is less toxic than letting the player die, but visible cast times keep skill expression.

Aggro, friendly fire and resources

  • Companions should not pull distant packs unless the player initiates or uses a “attack my target” command.
  • Friendly fire off by default; environmental hazards may still hurt them if stakes require it.
  • Shared resource pools (mana, ammo) need UI clarity; separate pools reduce frustration but weaken co-op fantasy.
  • On companion death, prefer downed state + revive over permanent loss unless roguelike rules apply.

Expose a tactics overlay (aggressive / balanced / passive) and a ping system. Players who want full control get it; players who want hands-off support leave defaults. Never hide the mode — a HUD icon beats a buried options menu.

Barks, personality and context triggers

Companions feel smart when they comment on the world, not when they win aim duels. A bark system is a lightweight state machine or scriptable object graph:

  • Cooldown buckets — combat, exploration, story; max one bark per bucket per 30–90 s unless critical.
  • Context tagslow_player_hp, new_lore_item, boss_phase_2, stealth_detected.
  • Personality filters — scholar uses longer lines; scout uses short callouts. Same trigger, different voice.
  • Priority overrides — story-critical lines interrupt idle chatter; never interrupt player dialogue choices.

Pair barks with optional gestures (point, kneel, scan animation) so companions sell intent without extra VO budget every session. For deeper conversational systems, layer dialogue trees on top of the bark layer rather than replacing follow/combat AI with branching scripts.

Harbor Ruins escort refactor (worked example)

The beta fixes shipped in three passes:

  1. Navmesh pass — Added doorway yield volumes on all single-tile exits; stuck timer teleports with 0.3 s dissolve; scholar marked non-combatant and invulnerable outside boss arenas.
  2. Combat pass — Scout weak-point tags only apply to enemies the player has hit once; scout DPS cap lowered from 55% to 32% of player rifle; new ping “focus target” forces priority 3 for 8 s.
  3. Presentation pass — Tactics icon in HUD (balanced default); bark buckets throttled; boss entry trigger forces rail-locked positions until intro VO completes.

Post-patch: doorway deaths fell from 41% to 6% of total deaths, boss wipe rate on first attempt dropped 18%, and “companion stuck” tickets went to near zero. Players described the scout as “useful” in surveys instead of “in the way.” The lesson: most companion work is navigation and threat etiquette, not fancier attack selectors.

Architecture decision table

Approach Best for Trade-offs
Scripted splines + triggers Escort missions, linear chapters, cinematic set pieces Breaks in open hubs; high authoring cost per level
Follow + slot navmesh Action-adventure, RPG exploration, most party followers Needs doorway/stuck policies; tuning per biome
Behavior tree combat leaves Combatants with clear modes (cover, suppress, heal) Designer-heavy; pair with player tactics overlay
Utility AI goal picker Choosing heal vs attack vs buff under pressure Does not replace pathing; opaque without debug UI
Direct player commands Tactical RPGs, RTS-style squads, summon pets More UI; slower pace; highest agency, lowest surprise

Hybrid stacks win: follow navmesh in explore, behavior tree in combat, utility layer only for ability choice. Keep enemy AI and companion AI in separate blackboards so tuning one does not break the other.

Pitfalls

  • Doorway hugging. The default navmesh “nearest to player” goal blocks exits; use slots and yield volumes.
  • Kill stealing. Companions finishing every enemy removes loot satisfaction and mastery feedback.
  • Off-screen suicide. Companions that engage beyond camera frustum die without player awareness; leash combat radius.
  • Cutscene drift. Companions pathing during dialogue break immersion; freeze or rail-lock during conversations.
  • Identical companions. Clone AI with different skins wastes narrative investment; vary priorities and barks.
  • No debug overlay. Without slot gizmos and priority logs, designers blame level art for AI failures.
  • Permanent death. Losing a story companion to random trash pack ends campaigns; use downed states or story immunity.

Production checklist

  • Document archetype and autonomy mode per companion (explore vs combat).
  • Implement formation slots, doorway yield, stuck teleport, and three-distance leash.
  • Define combat priority stack with assist bias toward player targets.
  • Cap companion DPS or healing throughput relative to solo player power.
  • Ship tactics overlay or ping commands; surface current mode in HUD.
  • Build bark buckets with cooldowns and personality-specific lines.
  • Add downed/revive flow instead of instant permanent death (unless genre demands).
  • Validate netcode authority for multiplayer followers.
  • Playtest narrow corridors, elevators, and boss intros with metrics on companion-related deaths.
  • Provide designer debug draw for slots, paths, and active combat priorities.

Key takeaways

  • Companion AI is navigation and etiquette first — combat intelligence matters only after followers stop blocking doors.
  • Match autonomy to archetype — escorts need reliability; combatants need readable assist rules.
  • Formation slots and doorway yield eliminate the majority of player frustration in playtests.
  • Priority stacks and DPS caps keep companions helpful without stealing agency.
  • Barks sell personality cheaply — context triggers beat smarter aiming for perceived intelligence.

Related reading