Beginner

NavMesh Navigation

Unity's NavMesh system provides built-in pathfinding, obstacle avoidance, and agent movement for 3D game worlds.

Setting Up NavMesh

  1. Mark Static Geometry

    Select your floor, walls, and obstacles in the scene. Mark them as "Navigation Static" in the Inspector.

  2. Bake the NavMesh

    Open Window → AI → Navigation. Click the "Bake" tab and press "Bake". Unity generates the walkable mesh shown as a blue overlay.

  3. Add NavMeshAgent

    Add a NavMeshAgent component to your character. This handles pathfinding, movement, and obstacle avoidance automatically.

  4. Set Destination

    Call agent.SetDestination(targetPosition) in your script to move the agent.

NavMeshAgent Properties

PropertyDescriptionTypical Value
SpeedMaximum movement speed3.5
Angular SpeedTurning speed in degrees/sec120
AccelerationHow quickly the agent reaches max speed8
Stopping DistanceDistance from target where agent stops0.5
Avoidance PriorityLower numbers get right-of-way (0-99)50
RadiusAgent collision radius for avoidance0.5
C# - Click-to-Move Navigation
using UnityEngine;
using UnityEngine.AI;

public class ClickToMove : MonoBehaviour
{
    private NavMeshAgent agent;
    private Camera cam;

    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        cam = Camera.main;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                agent.SetDestination(hit.point);
            }
        }
    }
}

Dynamic Obstacles

Use NavMeshObstacle for objects that move at runtime. Enable "Carve" to cut holes in the NavMesh dynamically, forcing agents to path around them.

OffMeshLinks

OffMeshLinks connect disconnected NavMesh areas, enabling agents to jump across gaps, climb ladders, or use teleporters. You can auto-generate them or place them manually for precise control.

NavMesh Surface (New API)

The modern AI Navigation package uses NavMeshSurface components instead of the legacy baking window. Benefits include runtime baking, per-surface configuration, and better support for procedural levels.

Key takeaway: Unity's NavMesh system provides robust, out-of-the-box pathfinding. Mark your geometry, bake the mesh, add a NavMeshAgent, and call SetDestination. For dynamic worlds, use NavMeshObstacle and the new NavMeshSurface API.