Ai Behavior System
AI Behavior System
Section titled “AI Behavior System”AI Aggro Implementation
Section titled “AI Aggro Implementation”Detection Range Setup
Section titled “Detection Range Setup”Create AI aggro system for enemy detection and engagement:
Aggro Collision Sphere
Section titled “Aggro Collision Sphere”- Component: Sphere collision named “CollisionSphere_Aggro”
- Position: At AI character feet (Z location -90)
- Radius: 800 units for detection range
- Collision Settings: Custom collision, ignore all, overlap pawn only
Player Detection System
Section titled “Player Detection System”Implement player-specific detection to prevent AI attacking each other:
Character Type Interface
Section titled “Character Type Interface”Create interface function to identify character types:
- Interface_Character_Type: Returns boolean for player identification
- Player Character: Returns true
- AI Characters: Returns false (default)
- NPC Characters: Returns false
Aggro Trigger Logic
Section titled “Aggro Trigger Logic”// AI Aggro DetectionOnAggroSphereOverlap(OtherActor) {if (OtherActor.Interface_Character_Type()) {// This is the player characterF_Aggro_Player(OtherActor);CE_SpawnLocation_Leash(); // Start leash timer}}
AI Leash System
Section titled “AI Leash System”Spawn Location Management
Section titled “Spawn Location Management”Prevent AI from wandering too far from spawn point:
Leash Variables
Section titled “Leash Variables”- Spawn_Location Vector: Store original spawn position on begin play
- Leash_Distance Float: Maximum distance from spawn (default 1000 units)
- Timer_Check_Leash_Distance: Periodic distance checking
Leash Implementation
Section titled “Leash Implementation”// AI Leash SystemCE_SpawnLocation_Leash() {Timer_Check_Leash_Distance = CreateTimer(1.0, true); // Check every second}
CE_CheckLeashDistance() {current_distance = Distance(GetActorLocation(), Spawn_Location);
if (current_distance > Leash_Distance) {CE_Reset_AI_Character();}}
AI Reset Process
Section titled “AI Reset Process”Return AI to spawn location when leash exceeded:
// AI Character ResetCE_Reset_AI_Character() {StopMovementImmediately();DisableAggroCollision();
AI_Move_To(Spawn_Location, false); // Move to location, not actor
// Wait for arrival before re-enablingTimer_CheckForSpawnLocation(1.0, true);}
AI Movement System
Section titled “AI Movement System”Consolidated Move Function
Section titled “Consolidated Move Function”Create single function for all AI movement needs:
F_AI_Move_To Function
Section titled “F_AI_Move_To Function”- Vector Input: Target location
- Actor Input: Target actor to follow
- Use_Actor Boolean: Choose between location and actor movement
- Conditional Logic: Prevent movement during reset or death states
Movement Validation
Section titled “Movement Validation”// AI Movement with ConditionsF_AI_Move_To(Location, Actor, Use_Actor) {if (!Dead && !Reset) {if (Use_Actor) {MoveToActor(Actor, AcceptanceRadius);} else {MoveToLocation(Location, AcceptanceRadius);}}}
Player Detection Phases
Section titled “Player Detection Phases”Three-Phase Detection System
Section titled “Three-Phase Detection System”Implement escalating AI response to player presence:
Detection Value System
Section titled “Detection Value System”- Player_Detection Integer: Accumulates detection level
- Phase Thresholds: 33, 66, 100 for different behaviors
- Value Sources: Player noise, visual contact, damage taken
Detection Phases
Section titled “Detection Phases”// AI Detection PhasesOnDetectionUpdate(Value) {Player_Detection += Value;
if (Player_Detection < 33) {// Phase 0: No responsereturn;} else if (Player_Detection < 66) {// Phase 1: Look at player directionLookAtPlayer(Player_Detected);} else if (Player_Detection < 100) {// Phase 2: Walk to player locationSetMoveSpeed(Walk);AI_Move_To(Player_Detected.Location, true);} else {// Phase 3: Attack playerSetMoveSpeed(Run);F_Aggro_Player(Player_Detected);}}
Combat Integration
Section titled “Combat Integration”Aggro on Damage
Section titled “Aggro on Damage”Immediate aggro when AI receives damage:
Damage Response System
Section titled “Damage Response System”- Last_Attacker Variable: Track who damaged this AI
- Player Check: Verify attacker is player character
- Immediate Aggro: Skip detection phases and go straight to combat
// AI Damage ResponseF_On_Damage_Received() {if (Last_Attacker.Interface_Character_Type()) {// Immediate aggro on player damageF_Aggro_Player(Last_Attacker);}}
State Reset Integration
Section titled “State Reset Integration”- Death Reset: Clear detection values when AI dies
- Leash Reset: Reset detection when returning to spawn
- Combat End: Gradually reduce detection over time
The AI behavior system creates engaging, predictable enemy encounters with proper state management and realistic response patterns that enhance gameplay without creating frustrating or confusing AI behavior.