Skip to content
smsolutionsva-byte edited this page Jun 26, 2026 · 2 revisions

AI

Home · Enemies · World · Game-Systems

Enemy behavior combines per-enemy perception, squad-style approach lanes, obstacle avoidance, bullet dodging, attack state machines, predictive spawning, and adaptive difficulty. Most expensive decisions are throttled or allocation-conscious so combat remains viable with many entities.

Behavior states

The decision system exposes patrol, hunt, attack, and investigate as active gameplay states. The type definition also includes idle, retreat, coordinate, and ambush, but the current decision path does not select retreat: damaged enemies keep pressing the player rather than fleeing.

State Trigger Behavior
Patrol No sight, sound, or alert Moves around a small local patrol ring.
Investigate Stored disturbance / last known position Travels to the disturbance, then falls back to patrol.
Hunt Player seen, heard, or sufficiently alerted Uses a stable per-enemy approach lane to form a surround.
Attack Melee enemy sees the player within close range Commits toward a slightly led target and starts the telegraphed attack cycle.

Squad approach and navigation

Each enemy receives a stable flank sign, flank strength, speed trim, and—in the Ranged case—standoff distance. Melee units bend their approach from different sides at long range, then reduce the bend inside about five units to commit directly into melee. This avoids a single-file rush and avoids endless orbiting.

Ranged support enemies hold a 14–21 unit kiting ring in their AI layer, then use their separate bolt rules when they have an appropriate 6–50 unit line of sight.

Obstacle avoidance combines direct-path checking, terrain repulsion, tangential wall sliding, personal-space separation, and stuck recovery. Tanks/Bosses get larger personal-space values. Navigation uses map collision props rather than a baked navigation mesh; no NavMesh or A* asset pipeline was found.

Perception and aggro

  • Enemy vision uses a cone and terrain line-of-sight test, though live enemy configuration grants 360° vision with a 500-unit nominal range.
  • Hearing responds to movement and gunfire; sound memory lasts five seconds.
  • Night reduces the perception system's default visual range multiplier to 70%, although live high range and engagement culling also apply.
  • Difficulty scales aggro distance, reaction time, and the range in which expensive AI stays active.
  • Trees and collidable props block Sniper and Sentinel line of sight.

Bullet dodging

Bullet dodging scans projectiles within 15 units (20 for Fast enemies), estimates closest approach, and only reacts to threatening trajectories. Dodges have a base two-second cooldown, reaction-time gate, success probability, and a sideways/backward randomized escape direction. Wave number increases dodge skill and shortens the cooldown; Hard reacts faster than Easy.

Attack logic

Melee attacks have wind-up, strike, and recovery animation phases. Damage is allowed once in the strike phase, with range and frontal-arc checks plus an overlap fallback. The system animates arm swings, torso rotation, and a short forward lunge so attacks are telegraphed rather than passive contact damage.

Snipers and Revenants use their own energy-bolt logic; Snipers do not enter the melee attack path. Revenants combine gold-bolt attacks with a close-range melee option.

Spawning and adaptive systems

The spawn system tracks movement history, kills, recent spawn areas, and player behavior indicators. It can score candidate positions for distance, player movement direction, anti-camping, flanking, and local enemy density. The live wave spawner additionally distributes a batch around the player at evenly spaced bearings.

Adaptive difficulty records hits, accuracy, kills, health, and survival behavior. In Adaptive mode it periodically updates future enemy health, damage, spawn rate, and a smoothed speed target. It is an implementation-driven dynamic system, not a fixed difficulty preset.

Performance behavior

Enemy meshes are pooled and reuse geometry/materials. High, medium, low, and culled LODs transition at 45, 70, and 100 units, with shadows disabled beyond 40 units. Enemies are only damageable while their high-detail representation is active; this prevents long-range shots against minimal distant stand-ins.

Implementation references: src/utils/AIBehaviorSystem.ts, src/utils/EnemyPerception.ts, src/utils/AttackSystem.ts, src/utils/ObstacleAvoidance.ts, src/utils/BulletDodging.ts, src/utils/PredictiveSpawnSystem.ts, src/utils/AdaptiveDifficultySystem.ts, src/utils/SmartEnemyManager.ts.

Clone this wiki locally