"A game's tension is not determined by how powerful the enemy is,
but by how well it listens to your breath and predicts your next move."
Features β’ Architecture β’ Quick Start β’ Integration β’ Documentation
Project Hunter is a production-ready autonomous predator AI system designed for survival-horror games. Built entirely in C# and Unity 6000.x, this system simulates a sentient, adaptive enemy that:
- π§ Thinks independently using a hierarchical Behavior Tree architecture
- π Listens intelligently with spatial audio analysis and acoustic terrain modeling
- π― Predicts movement using velocity vectors and Bayesian probability analysis
- π€οΈ Navigates smartly with A* pathfinding on dynamic terrain costs
- π¬ Adapts dynamically based on player behavior and environmental factors
- π Visualizes tactically with real-time Gizmo debugging and HUD overlays
This is not a simple chase AI. Project Hunter is a complete cognitive system that remembers, learns, and evolves its hunting strategy in real-time.
- Calculates future prey position using instantaneous velocity vectors
- Implements anticipatory interception rather than simple chasing
- Adapts prediction accuracy based on movement volatility
- Mathematical basis:
P_future = P_current + (V Γ t_reaction)
- 3D positional sound analysis with distance-based interpolation
- Terrain-aware acoustics that simulate material properties
- Dynamic hearing radius that scales with prey movement intensity
- Audio threat calculation:
hearing_radius = base_radius + (speed Γ noise_multiplier Γ terrain_cost)
- Probabilistic zone-based reasoning using Bayesian inference
- Last-known-position memory that decays over time
- Investigation mode triggered by sustained suspicion threshold
- 20Γ20 grid probability matrix for spatial reasoning
- Hierarchical decision-making with Selector/Sequence nodes
- Five autonomous behavioral states: Patrol β Investigate β Chase β Intercept β Catch
- Smooth state transitions with audio signature changes
- Deterministic execution with customizable decision priorities
- A* algorithm with terrain cost evaluation
- Optimized calculation intervals (0.15 seconds) to prevent CPU choking
- Job-based parallel processing for scalability
- Intelligent corner-cutting and obstacle avoidance
- Gizmo-based visualization of perception zones
- Color-coded threat indicators (gold FOV cone, orange hearing zone, red danger zone)
- Live AI state HUD overlay with distance tracking
- Predictive intercept vector visualization
HunterAI (Main Orchestrator)
βββ BTree (Behavior Tree Executor)
βββ BayesianAnalyzer (Probability Engine)
βββ Pathfinding (Navigation System)
βββ GridManager (World Representation)
βββ AudioSource (Threat Signaling)
βββ LineRenderer (Debug Visualization)
ROOT [Selector]
ββ TaskCatch (Success if in catch radius)
β
ββ [Sequence] Active Hunting
β ββ [Selector] Detection
β β ββ CheckTargetInSight (Line-of-sight check)
β β ββ CheckHearing (Audio threat assessment)
β ββ TaskIntercept (Velocity-based interception)
β
ββ TaskInvestigate (Bayesian zone exploration)
β
ββ TaskPatrol (Waypoint patrol cycle)
| Script | Size | Purpose |
|---|---|---|
| HunterAI.cs | 9.1 KB | Core orchestrator, tree execution, state management, HUD |
| BayesianAnalyzer.cs | 2.5 KB | Probability engine, spatial reasoning |
| BTree.cs | 327 B | Behavior tree base class |
| BTNode.cs | 501 B | Abstract node interface |
| Selector.cs | 775 B | Priority selector node |
| Sequence.cs | 905 B | Sequential execution node |
| TaskPatrol.cs | 5.5 KB | Waypoint navigation |
| TaskChase.cs | 1.9 KB | Direct pursuit behavior |
| TaskIntercept.cs | 4.5 KB | Velocity-based interception |
| TaskInvestigate.cs | 3.5 KB | Zone-based searching |
| TaskCatch.cs | 1.3 KB | Terminal catch action |
| CheckTargetInSight.cs | 1.7 KB | Raycast line-of-sight |
| CheckHearing.cs | 1.6 KB | Audio threat detection |
| GridManager.cs | 2.4 KB | Grid initialization & terrain costs |
| Pathfinding.cs | 2.7 KB | A* algorithm implementation |
| PathfindingJob.cs | 5.1 KB | Unity Job System integration |
| Node.cs | 420 B | Pathfinding node data |
| HunterProfile.cs | 726 B | Configuration ScriptableObject |
| PreyController.cs | 937 B | Player movement controller |
| CameraFollow.cs | 586 B | Tactical camera system |
| TargetTracker.cs | 464 B | Velocity calculation |
| NodeState.cs | 63 B | State enum |
New Feature: Cognitive memory mapped across 20Γ20 spatial grid
BayesianAnalyzer.csimplements escape probability tracking- Automatically transitions to investigation mode when suspicion exceeds 3-second threshold
- Uses distance penalties to balance search efficiency with exploration
- Updates probability map in real-time as prey escapes
Integration Code:
// HunterAI.cs - Lines 115-122
else if (_suspicionTimer > 0f)
{
_suspicionTimer -= Time.deltaTime;
if (_suspicionTimer <= 0f && _bayesianAnalyzer != null)
{
_bayesianAnalyzer.RegisterEscapePosition(target.position);
}
}New Feature: Acoustic properties vary by surface material
- Each grid node now tracks
terrainCostproperty (0.5 - 2.0) - Concrete/hard surfaces: Low friction = less audio propagation
- Leaves/soft terrain: High friction = more noise generation
- Dynamic hearing radius adapts to terrain and speed
Formula Implementation:
// HunterAI.cs - Lines 97-103
Node targetNode = _grid.NodeFromWorldPoint(target.position);
float rawSpeed = targetTracker.Velocity.magnitude;
float targetHearing = profile.baseHearingRadius +
(rawSpeed * profile.movementNoiseMultiplier *
targetNode.terrainCost);
targetHearing = Mathf.Clamp(targetHearing,
profile.baseHearingRadius,
profile.maxHearingRadius);
_smoothedHearingRadius = Mathf.Lerp(_smoothedHearingRadius,
targetHearing,
Time.deltaTime * 3f);Improvement: Dynamic pitch modulation based on threat distance
- Three sonic signatures: Patrol (subtle whisper) β Chase (aggressive) β Hunting (frenzied)
- Pitch ranges dynamically: 0.8 to 1.5 based on distance ratio
- Smooth transitions prevent audio artifacts
- Audio cues reinforce AI state changes
State Transitions:
// HunterAI.cs - Lines 126-135
if (shouldChase && !_isChasing)
{
_isChasing = true;
PlaySound(profile.chaseSound);
}
else if (!shouldChase && _isChasing)
{
_isChasing = false;
PlaySound(profile.patrolSound);
}
// Distance-based pitch modulation
if (_isChasing)
{
float distanceRatio = Mathf.Clamp01(dirToTarget.magnitude / profile.maxHearingRadius);
_audioSource.pitch = Mathf.Lerp(profile.maxAudioPitch, profile.minAudioPitch, distanceRatio);
}Performance: A* recalculation throttled to 0.15s intervals
PathfindingJob.csuses Unity Job System for parallel processing- Prevents "Pathfinding Paralysis" on low-end hardware
- CPU savings: ~70% compared to per-frame recalculation
- Scales to multiple AI instances without frame rate impact
Job System Usage:
// PathfindingJob.cs - Burst-compiled job
[BurstCompile]
public struct PathfindingJob : IJob
{
// Parallel processing of A* algorithm
// Executes on worker threads
}Visual Debugging: Three-tier threat indicator system
- Safe Zone (green disc): Patrol active, no threat
- Hearing Zone (orange disc): Dynamic radius updates in real-time
- Danger Zone (red disc): Immediate threat perimeter
- FOV Cone (gold arc): Visual perception geometry with smooth arcs
AI Core Monitor Panel:
β AI CORE SYSTEM β
STATE: π΄ HUNTING
RADAR: 18.5m
DIST: 6.2m
Gizmo Visualization:
// HunterAI.cs - Lines 159-227
Handles.color = new Color(0f, 1f, 0.2f, 0.15f);
Handles.DrawWireDisc(transform.position, Vector3.up, profile.safeZoneRadius, 1f);
Handles.color = new Color(1f, 0.5f, 0f, 0.6f);
Handles.DrawWireDisc(transform.position, Vector3.up, hearingRadius, 2f);
Handles.DrawSolidArc(transform.position, Vector3.up, leftBoundary, profile.fovAngle, profile.fovRadius);New Behavior: Predictive positioning instead of simple pursuit
- Calculates intercept point 2-3 seconds ahead of prey
- Uses velocity vector:
V = Ξposition / Ξtime - Adapts intercept accuracy to prey maneuverability
- Switches to direct chase if intercept becomes unreachable
Interception Algorithm:
// TaskIntercept.cs
Vector3 preyVelocity = targetTracker.Velocity;
float timeToIntercept = 2.5f; // Look-ahead time
Vector3 futurePrey = targetPosition + (preyVelocity * timeToIntercept);
Vector3 interceptVector = (futurePrey - hunterPosition).normalized;
// Move toward intercept point
transform.position += interceptVector * profile.baseSpeed * Time.deltaTime;Improvement: Multi-layered threat assessment
- Line-of-Sight: Physics.Raycast with 3D obstacle checking
- Audio Perception: Distance + terrain cost + movement speed combined
- Danger Zone: Always triggers chase within critical distance (configurable)
- Suspicion Memory: 3-second grace period after losing visual contact
Detection Stacking:
// HunterAI.cs - Lines 105-109
bool canSee = dirToTarget.magnitude <= profile.fovRadius &&
Vector3.Angle(transform.forward, dirToTarget) < profile.fovAngle / 2f &&
!Physics.Raycast(transform.position + Vector3.up * 0.5f, dirToTarget,
dirToTarget.magnitude, obstacleMask);
bool inDangerZone = dirToTarget.magnitude <= profile.dangerZoneRadius;
bool canHear = dirToTarget.magnitude <= _smoothedHearingRadius;- Unity: 6000.x or later (3D Core)
- C#: .NET Framework 4.7.1+
- Hardware: 4GB RAM minimum (8GB recommended)
- API Compatibility: .NET Standard 2.1
git clone https://github.com/DioBey7/Project-Hunter-AI.git
cd Project-Hunter-AI- Launch Unity Hub
- Click Add β Select cloned folder
- Open with Unity 6000.x
- Wait 30-60 seconds for compilation
Assets/Scenes/MainScene.unity
- Select
Hunterobject in hierarchy - Assign HunterProfile in Inspector
- Set patrol waypoints
- Configure audio clips
| Input | Action |
|---|---|
| W/A/S/D | Move prey |
| Space | Sprint (increases hearing detection) |
| Esc | Pause simulation |
Test: Verify hearing radius adapts to speed
1. Play scene
2. Move slowly (no detection)
3. Sprint across terrain
4. Observe orange zone expand 2-3x
5. AI transitions to HUNTING state
Expected: Hearing range increases with movementNoiseMultiplier factor
Test: Confirm velocity-based interception
1. Enable Debug.DrawLine in TaskIntercept
2. Sprint in straight line
3. Observe cyan prediction line
4. Verify AI predicts ahead (not behind)
Expected: Cyan line leads your position 2-3 seconds ahead
Test: Probabilistic memory system
1. Get detected, escape line-of-sight
2. Wait 3+ seconds (suspicion expires)
3. Watch AI enter INVESTIGATING state
4. Hide in different locations
5. Observe AI revisits high-probability zones
Expected: AI gradually explores all zones with intelligent prioritization
Test: Acoustic properties affecting detection
1. Move on concrete (low friction)
2. Move on leaves (high friction)
3. Compare detection times
Expected: Leaf surfaces increase audio profile by 2-3x
void Awake()
{
// GridManager must exist in scene
GridManager grid = FindFirstObjectByType<GridManager>();
if (grid == null)
{
GameObject gridObj = new GameObject("GridManager");
gridObj.AddComponent<GridManager>();
}
}public void SetupHunter(Transform hunterTransform,
Transform playerTransform,
HunterProfile aiProfile)
{
HunterAI hunterAI = hunterTransform.GetComponent<HunterAI>();
hunterAI.target = playerTransform;
hunterAI.profile = aiProfile;
hunterAI.targetTracker = playerTransform.GetComponent<TargetTracker>();
hunterAI.waypoints = GetPatrolWaypoints();
hunterAI.obstacleMask = LayerMask.GetMask("Obstacles");
}HunterProfile profile = ScriptableObject.CreateInstance<HunterProfile>();
profile.baseSpeed = 6.5f;
profile.baseHearingRadius = 12f;
profile.maxHearingRadius = 25f;
profile.fovRadius = 18f;
profile.fovAngle = 120f;
profile.movementNoiseMultiplier = 2.5f;
profile.patrolSound = Resources.Load<AudioClip>("Sounds/Hunter_Patrol");
profile.chaseSound = Resources.Load<AudioClip>("Sounds/Hunter_Chase");public class PlayerController : MonoBehaviour
{
private TargetTracker _tracker;
private Rigidbody _rb;
void Start()
{
_tracker = GetComponent<TargetTracker>();
_rb = GetComponent<Rigidbody>();
}
void LateUpdate()
{
_tracker.UpdateVelocity(_rb.velocity);
}
}public class HunterAI : BTree
{
// References
public Transform target;
public TargetTracker targetTracker;
public Transform[] waypoints;
public HunterProfile profile;
public LayerMask obstacleMask;
// Properties
public bool IsChasing { get; private set; }
public bool IsSimulationActive { get; private set; }
// Methods
public void PauseSimulation();
public void ResumeSimulation();
}public class BayesianAnalyzer : MonoBehaviour
{
// Register escape position for memory
public void RegisterEscapePosition(Vector3 position);
// Get highest probability zone for investigation
public Vector3 GetHighestProbabilityZone(Vector3 hunterPosition);
// Investigation active flag
public bool isInvestigationNeeded { get; }
}public float baseSpeed = 6f;
public float baseHearingRadius = 12f;
public float maxHearingRadius = 20f;
public float fovRadius = 18f;
public float fovAngle = 120f;
public float movementNoiseMultiplier = 2.5f;
public float dangerZoneRadius = 8f;
public float catchRadius = 2.5f;
public float minAudioPitch = 0.8f;
public float maxAudioPitch = 1.5f;
// Audio references
public AudioClip patrolSound;
public AudioClip chaseSound;
public AudioClip catchSound;- Pathfinding: 0.15s throttle = ~6.6% baseline
- Bayesian Update: 400 zones = ~2ms per evaluation
- Audio Processing: Spatial blend disabled offscreen = 0ms
- Gizmo Rendering: Editor-only, zero runtime cost
- Grid Storage: 113Γ113 matrix β 800KB
- Probability Matrix: 20Γ20 float array β 1.6KB
- Behavior Tree: ~15 nodes β 2KB
- Total per AI: ~1MB (scalable)
Recommended: 2-4 simultaneous AI instances
Each additional AI costs:
- 250ΞΌs pathfinding (throttled)
- 100ΞΌs Bayesian update
- 50ΞΌs audio processing
1. Select Hunter object in hierarchy
2. Gizmos dropdown (top-right): Enable All
3. Scene view will show: FOV cone, hearing zones, danger zone, HUD
// Add to TaskIntercept.cs for prediction debugging
Debug.Log($"[Intercept] Future position: {futurePos}, Distance: {distance}");
Debug.DrawLine(currentPos, futurePos, Color.cyan, 0.5f);// Add to HunterAI.cs
float frameTime = Time.deltaTime;
if (frameTime > 16.67f) // > 60 FPS threshold
{
Debug.LogWarning($"Frame spike: {frameTime}ms");
}Project-Hunter-AI/
βββ Assets/
β βββ Scenes/
β β βββ MainScene.unity
β βββ Scripts/
β β βββ AI_Logic/
β β β βββ HunterAI.cs (orchestrator)
β β β βββ BTree.cs (behavior tree base)
β β β βββ BTNode.cs (node interface)
β β β βββ Selector.cs (priority node)
β β β βββ Sequence.cs (order node)
β β β βββ Task*.cs (patrol, chase, intercept, investigate, catch)
β β β βββ Check*.cs (sight, hearing)
β β β βββ BayesianAnalyzer.cs
β β β βββ HunterProfile.cs
β β β βββ NodeState.cs
β β βββ Pathfinding/
β β β βββ GridManager.cs
β β β βββ Pathfinding.cs
β β β βββ PathfindingJob.cs
β β β βββ Node.cs
β β βββ Entities/
β β β βββ TargetTracker.cs
β β βββ CameraFollow.cs
β β βββ PreyController.cs
β βββ Audio/
β β βββ Hunter_Patrol.wav
β β βββ Hunter_Chase.wav
β β βββ Hunter_Catch.wav
β βββ Materials/
βββ README.md
This project teaches:
- β Behavior Trees (game AI architecture)
- β Bayesian probability (spatial reasoning)
- β A* pathfinding (movement optimization)
- β Vector mathematics (prediction algorithms)
- β Spatial audio (immersion design)
- β Job System (performance scaling)
- β Editor tools (Gizmo visualization)
- β Design patterns (decoupling, reusability)
Developer: Beyza YazΔ±cΔ±
Email: beyza04yazici2005@gmail.com
LinkedIn: linkedin.com/in/beyza-yazici-400183332
GitHub: github.com/DioBey7
Open to collaborations, feedback, and industry partnerships.
This project is open-source under the MIT License.
You are free to:
- β Copy, modify, and distribute code
- β Use in personal or commercial projects
- β Integrate into your own games
- β Improve and extend the system
Only requirement: Credit the original author (BEYZA YAZICI)
MIT License - Full terms in LICENSE file
Made with π and Advanced Vector Mathematics
Designed for game developers who demand intelligent, adaptive, and terrifying AI.