NavMesh (Navigation Mesh) is a simplified map of your scene that tells AI where it can walk. Unity's NavMesh system calculates paths and moves characters around obstacles automatically.
- AI moves around walls and obstacles
- Finds shortest path automatically
- No need for complex pathfinding code

1. Setting Up NavMesh
Step 1: Open Navigation window: Window - AI - Navigation.
Step 2: Mark objects as walkable or not
- Select floor/ground objects
- Check "Navigation Static" in Inspector
Step 3: Mark obstacles (walls, trees, rocks)
- Select obstacle objects.
- Check "Navigation Static".
- Set Navigation Area to "Not Walkable".
Step 4: Bake the NavMesh.
- Navigation window - Bake tab.
- Click "Bake" button.
The blue area appears in Scene view showing where AI can walk.
2. Adding NavMesh Agent to Enemy
The NavMesh Agent component moves the enemy along the calculated path.
Step 1: Select your enemy GameObject.
Step 2: Add Component - NavMeshAgent.
Important settings:
| Setting | Value | What it does |
|---|---|---|
| Speed | 3.5 | Controls movement speed |
| Angular Speed | 120 | Controls how fast the agent turns |
| Acceleration | 8 | Determines how quickly it reaches full speed |
| Stopping Distance | 1 | Distance from target where the agent stops |
| Radius | 0.5 | Defines size for obstacle avoidance |
| Height | 2 | Sets the height of the agent |
3. Making Enemy Follow Player
Example:
using UnityEngine;
using UnityEngine.AI;
public class EnemyAI : MonoBehaviour
{
public Transform player;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
// Find player by tag if not assigned
if (player == null)
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
}
void Update()
{
// Set enemy destination to player position
agent.SetDestination(player.position);
}
}
Output:

agent.SetDestination() tells the enemy where to go. NavMeshAgent automatically finds the path and moves there.
NavMesh vs Simple Movement
| Feature | NavMesh | Simple Movement |
|---|---|---|
| Pathfinding | Automatic pathfinding | Manual movement logic required |
| Obstacle Handling | Automatically avoids obstacles | Requires custom handling |
| Use Case | Best for complex environments (AI, enemies) | Best for simple/open areas |
| Performance | Slightly heavier | Lightweight and faster |
| Implementation | Easier for navigation logic | Requires more manual coding |
Common NavMesh Issues
- Enemy not moving check NavMeshAgent is attached and NavMesh is baked.
- Enemy stuck on walls increase Radius in NavMeshAgent.
- Enemy goes through obstacles re-bake NavMesh after scene changes.
- No blue area visible open Navigation - Bake and generate NavMesh.