Ai Patrol System
AI Patrol System
Section titled “AI Patrol System”Patrol Marker Setup
Section titled “Patrol Marker Setup”Patrol Marker Actor
Section titled “Patrol Marker Actor”Create visual waypoint system for AI patrol routes:
Actor Components
Section titled “Actor Components”- Sphere Component: Root component for positioning
- Dynamic Material: Translucent blue material for designer visibility
- Text Render Component: Display route information
- Collision Settings: No collision, hidden in game
Visual Configuration
Section titled “Visual Configuration”- Material: Light blue, 80% opacity for clear visibility
- Color Variable: Instance-editable for different route identification
- Text Display: Route order and naming information
Patrol Route Organization
Section titled “Patrol Route Organization”Tag-Based System
Section titled “Tag-Based System”Use Unreal Engine tags for route organization:
- Route Identifier: Letter tags (A, B, C) for different patrol routes
- Order Numbers: Number tags (1, 2, 3) for waypoint sequence
- Text Display: Shows both route letter and sequence number
Tag Implementation
Section titled “Tag Implementation”// Patrol Marker Display SystemOnConstruct() {route_name = Tags[1]; // Letter (A, B, C)route_point = Tags[0]; // Number (1, 2, 3)
display_text = route_name + ' ' + route_point;TextRender.SetText(display_text);}
Level Design Integration
Section titled “Level Design Integration”- Visual Clarity: Bright yellow text for high visibility
- Route Planning: Clear progression from point 1→2→3→2→1
- Multiple Routes: Different colored spheres for different patrol paths
AI Patrol Implementation
Section titled “AI Patrol Implementation”Patrol Route Setup
Section titled “Patrol Route Setup”Configure AI characters for patrol behavior:
Spawner Integration
Section titled “Spawner Integration”- Patrol Route Variable: Name-type variable on AI spawner
- Route Assignment: Spawner passes patrol route to spawned AI
- Interface Communication: Interface_Set_AI_Patrol_Route function
Route Discovery Process
Section titled “Route Discovery Process”// AI Route DiscoveryOnPatrolRouteAssignment(PatrolRouteName) {if (PatrolRouteName != 'None') {patrol_markers = GetAllActorsOfClassWithTag(Actor_Patrol_Marker, PatrolRouteName);SortMarkersByTag(patrol_markers); // Sort by number tagspatrol_route_array = sorted_markers;
DelayedStart(RandomFloat(1.0, 3.0)); // Stagger patrol startsCE_Patrol_Route();}}
Route Sorting Algorithm
Section titled “Route Sorting Algorithm”Sort patrol markers by number tags for proper sequence:
// Marker Sorting ImplementationSortMarkersByTag(UnsortedMarkers) {ForEach(marker in UnsortedMarkers) {tag_number = ConvertStringToInt(marker.Tags[0]);sorted_array[tag_number] = marker;}return sorted_array;}
Patrol Movement Logic
Section titled “Patrol Movement Logic”Bidirectional Patrol System
Section titled “Bidirectional Patrol System”Implement back-and-forth patrol movement:
Patrol State Variables
Section titled “Patrol State Variables”- Patrol_Index Integer: Current patrol point (starts at 1, ignores index 0)
- Patrol_Reverse Boolean: Direction of patrol movement
- Patrol_Destination Vector: Current target location
Patrol Direction Logic
Section titled “Patrol Direction Logic”// Bidirectional Patrol MovementOnReachDestination() {if (!Patrol_Reverse) {Patrol_Index++;if (Patrol_Index > LastArrayIndex) {Patrol_Reverse = true;Patrol_Index = LastArrayIndex - 1;}} else {Patrol_Index--;if (Patrol_Index < 1) {Patrol_Reverse = false;Patrol_Index = 1;}}
DelayedPatrolContinue(RandomFloat(1.0, 3.0));}
Movement Integration
Section titled “Movement Integration”Connect patrol system to AI movement:
- Move Speed: Set to walk during patrol
- AI_Move_To: Use location mode with patrol destinations
- Distance Check: Monitor arrival at patrol points (150-unit tolerance)
Patrol Interruption System
Section titled “Patrol Interruption System”Aggro Integration
Section titled “Aggro Integration”Handle player detection during patrol:
Detection Response
Section titled “Detection Response”- Stop Patrol: Clear patrol timers when player detected
- Combat Priority: Aggro behavior overrides patrol behavior
- Resume Delay: 10-second timer before resuming patrol after losing player
// Patrol Interruption ManagementOnPlayerAggro() {ClearAndInvalidateTimer(Timer_Patrol_Route);ClearAndInvalidateTimer(Timer_Check_Patrol_Destination);
// Set timer to resume patrol if player escapesTimer_Reset_Patrol = CreateTimer(10.0, false);}
State Management
Section titled “State Management”- Combat State: Patrol disabled during combat
- Death State: Stop all movement when AI dies
- Reset State: Return to patrol after leash reset
Patrol Polish Features
Section titled “Patrol Polish Features”Variable Patrol Timing
Section titled “Variable Patrol Timing”Add natural variance to patrol behavior:
- Random Delays: 1-3 second random pauses at waypoints
- Staggered Starts: 1-3 second random delay before initial patrol
- Human-Like Behavior: Prevents robotic, synchronized movement
Integration with Other Systems
Section titled “Integration with Other Systems”- Player Noise: Detection interrupts patrol
- Combat: Patrol resumes after combat ends
- Death/Respawn: Patrol restarts with respawned AI
- Leash System: Patrol continues from current progress after reset
The AI patrol system creates dynamic, believable enemy behavior that enhances level design possibilities while integrating seamlessly with combat and detection systems.