Enemy AI Kit
Complete enemy AI pipeline: state machine, patrol, chase, health, and wave spawning with debug visualization.
6 scripts intermediate Starter kit Complete AI pipeline for enemies
The full files for this kit are not published yet, so there is no download. 4 of its 6 scripts are in the library and linked below. The preview shows how the main pieces fit.
What is inside
- StateMachine.cs Not published yet
- State.cs Not published yet
- WaypointPatrol.cs Enemy patrol between waypoints with configurable speed, wait times, and patrol patterns (loop, ping-pong, random).
- EnemyChaseAI.cs Enemy AI that detects the player within radius, chases with line-of-sight, and returns to patrol when player escapes.
- HealthSystem.cs Reusable health component with damage, healing, invincibility frames, and events.
- WaveSpawner.cs Wave-based enemy spawner with configurable wave definitions, spawn points, delays, and wave completion callbacks.
What it does
- Finite state machine with clean enter/execute/exit lifecycle
- Waypoint patrol with loop, ping-pong, and random patterns
- Player detection with radius, FOV, and line-of-sight checks
- Chase behavior with give-up distance and return-to-origin
- Enemy health with damage, death events, and invincibility
- Wave-based spawning with configurable waves and spawn points
Setup, in order
- Import all scripts into your project
- Create enemy prefab with WaypointPatrol or EnemyChaseAI
- Place waypoint Transform objects in the scene for patrol routes
- Tag your player as 'Player' for detection to work
- Add HealthSystem to enemies for health tracking
- Set up WaveSpawner with spawn points and wave definitions
- For advanced AI, use StateMachine with custom State classes
- Select enemies in Scene to see debug gizmos (detection, patrol, FOV)
If something does not work
- Enemies never notice the player
- EnemyChaseAI looks for an object tagged Player. Tag your player, and put walls on a layer selected in Obstacle Layers so line of sight is blocked only by what should block it.
- Patrolling enemies stop at the first waypoint
- Assign at least two waypoints and pick a patrol mode (Loop, PingPong or Random). Waypoints must be reachable on the ground the enemy walks on.
Preview
An excerpt of the kit's main types, and the Inspector fields they expose.
Inspector
Fields from the kit's preview excerpt; the full kit has more.
Detection Radius 10
Field Of View 120
Chase Speed 5
On Player Detected ()
List is Empty
On Attack Range ()
List is Empty
Waypoints Transform · Size 0
Patrol Mode None (PatrolMode)
Excerpt
C#
// EnemyChaseAI.cs - Detection and chase
public class EnemyChaseAI : MonoBehaviour
{
[SerializeField] private float detectionRadius = 10f;
[SerializeField] private float fieldOfView = 120f;
[SerializeField] private float chaseSpeed = 5f;
public UnityEvent OnPlayerDetected;
public UnityEvent OnAttackRange;
// FOV + line-of-sight detection, chase, return to origin
}
// WaypointPatrol.cs - Patrol between points
public class WaypointPatrol : MonoBehaviour
{
[SerializeField] private Transform[] waypoints;
[SerializeField] private PatrolMode patrolMode;
// Loop, PingPong, Random patrol patterns
}Related
- Finite State MachineClean, extensible state machine for AI, player states, and game flow. Uses ScriptableObject states.
- FPS Foundation KitFirst-person shooter foundation with movement, camera, weapons, projectiles, health, and screen shake.
- Build a First-Person ShooterMovement, camera, weapons, projectiles, enemy AI, and screen effects for an FPS prototype.
- Build an RTS GameTop-down camera, click-to-move navigation, unit selection, minimap, and wave spawning for real-time strategy.