Enemy AI Starter Kit — Start Here
Three enemies, three worlds, one brain. This kit teaches enemy detection and pursuit — the sense → decide → act loop — through three one-click demos:
- 3D NavMesh enemy — patrols nav points; a long-range vision cone sees you and gives chase across a baked NavMesh; a short-range detector triggers attacks; break line of sight long enough and it returns to its patrol route.
- 2D top-down enemy — the same brain, but pathfinding runs on a complete, readable A* implementation you can actually study (~150 lines).
- 2D platformer enemies — the answer to "is there anything smarter than marching back and forth?": raycast feelers, forward-only vision cones, alert telegraphs, edge-aware chasing, and give-up leashes.
What you need
- Unity 6 (any 6.x).
- For the 3D demo: the AI Navigation package (
com.unity.ai.navigation) — included by default in Unity 6 template projects; install steps in 02 - Setup and NavMesh. - The 2D demos need nothing extra — the A* pathfinder is part of the kit.
What's in the kit
| Path | What it is |
|---|---|
Scripts/Enemy3D/TargetSensor.cs | Reusable detector: range + FOV cone + line of sight |
Scripts/Enemy3D/EnemyAI3D.cs | Patrol→Chase→Attack state machine on a NavMeshAgent |
Scripts/TopDown2D/GridPathfinder2D.cs | Full A* on an auto-baked grid |
Scripts/TopDown2D/EnemyAI2D.cs | The same FSM, driven by A* paths |
Scripts/Platformer2D/PlatformerEnemy2D.cs | Feelers, vision cone, alert, edge-aware chase |
Scripts/Common/ | Demo players, follow camera, damage flash |
Scripts/Editor/EnemyKitSetup.cs | One-click demo arenas + NavMesh auto-bake |
Tutorial/ | These lessons |
Fastest possible start (2 minutes)
- Open an empty scene.
- Tools → Enemy AI Starter Kit → Create 3D NavMesh Enemy Demo (the NavMesh bakes automatically).
- Press Play. WASD to move. Get seen, get chased, duck behind a wall until it gives up.
- Repeat with the 2D Top-Down and 2D Platformer demos — each in a fresh empty scene.
While playing, select the enemy in the Hierarchy: every sensor, feeler, patrol route, and A* path is drawn as gizmos in the Scene view. That live view is the best teaching aid in the kit.
Lesson path
- 01 - Enemy AI Concepts — the FSM and the sense→decide→act loop
- 02 - Setup and NavMesh — AI Navigation package, baking, agent settings
- 03 - The 3D Enemy — two detectors, chase, lose-sight, return to patrol
- 04 - A-Star for 2D Top-Down — how A* works, and reading the kit's implementation
- 05 - Platformer Enemies Beyond Back-and-Forth — feelers, cones, alerts, and when to graduate to node graphs
- 06 - Tuning and Extending — gizmos, tuning for difficulty, hearing, investigate states, behavior trees
Reference library
Official:
- AI Navigation package manual
- Adding AI Navigation — Unity Learn
- AI Navigation 2.0 video series (official)
Community:
- NavMesh pathfinding & enemy AI walkthrough
- AI patrol on a NavMesh (written)
- Enemy line of sight / stealth vision cones (video)
- Line of sight detection (written)
- A* Pathfinding Project — the production-grade 2D/3D pathfinder (2D guide)
- Generalized platformer AI pathfinding — GameDev.net
- 2D platformer pathfinding deep dive — Game Developer
Next: 01 - Enemy AI Concepts