[Godot] NavigationRegion2D and Navigation Meshes - Building a Map Your AI Can Walk On

Created: 2025-12-08Last updated: 2026-07-08

How NavigationRegion2D and navigation meshes work in Godot. Covers the difference from physics-based movement, baking the walkable area, keeping distance from walls with agent_radius, and handling moving obstacles with NavigationObstacle2D, all explained with diagrams.

An enemy that walks smoothly around walls and pillars to reach you feels smart. An enemy that bumps into a wall and shuffles left and right makes the whole game feel cheap.

In Godot, that smart movement is powered by NavigationRegion2D and a navigation mesh (a map made for AI). This article focuses on how to build that map. The agent that actually walks on it (the chase and patrol code) is covered in the companion article, Pathfinding with NavigationAgent2D. Here we go all the way through baking the walkable area.

Top-down 2D map with a blue polygon covering the walkable area around walls, and a dotted path routing around an obstacle

What You'll Learn

  • Why you need a navigation mesh (how it differs from physics-based movement)
  • How to bake the walkable area with NavigationRegion2D
  • How agent_radius keeps characters away from walls
  • How to avoid moving obstacles with NavigationObstacle2D
  • The agent that walks on this map is covered in the next article

Sponsored

Why You Need a Navigation Mesh

If all you want is "avoid obstacles," physics seems like it could do the job. The problem is that with physics, a character only learns a wall exists after hitting it. It charges into a dead end and then backs out. That looks unnatural, and it takes the long way around.

Comparison of physics-based movement bumping into a wall and turning back, versus a navmesh routing around the obstacle in advance
  • Physics-based: obstacles such as StaticBody2D are only recognized on collision. Discovering walls by crashing into them tends to look clumsy.
  • Navigation mesh: the walkable area is stored ahead of time as a polygon map, so the AI can compute a route around obstacles before it ever touches them.

NavigationRegion2D is the node that holds this "map for AI" and places it in your scene.

Baking a Mesh with NavigationRegion2D

Computing the walkable area to produce that map is called baking. Godot treats the collision shapes in your scene as obstacles and automatically calculates the gaps between them as walkable space.

Diagram showing that baking from stage walls and obstacles produces a blue, triangulated navigation mesh covering only the floor

The steps are simple.

  1. Build the stage: place walls and terrain using nodes that have a CollisionShape2D / CollisionPolygon2D, such as TileMap or StaticBody2D. These become the obstacles.
  2. Add a NavigationRegion2D: add the node, then create a new resource on navigation_polygon via "New NavigationPolygon."
  3. Bake it: with NavigationRegion2D selected, click "Bake NavigationPolygon" in the toolbar. On success, the walkable area appears as a semi-transparent blue polygon.

The NavigationPolygon resource itself has properties that control how baking behaves. Two of them matter most.

Property (NavigationPolygon)Role
agent_radiusThe agent's radius. Generates a mesh that keeps a safe distance from walls (covered below)
source_geometry_modeHow the source shapes for baking are collected. When building from a TileMap, use the group method and add the TileMap to the target group
Sponsored

Keeping Distance from Walls with agent_radius

If the baked mesh runs right up to the walls, a character's center can reach the very edge of the mesh, which means its body visually clips into the wall. agent_radius is what prevents that.

Top-down view with double-headed arrows showing the navmesh shrunk inward from the wall edge by agent_radius, so the character never clips into the wall

When you set agent_radius, the mesh is generated inset from walls by that radius. Since a character's center can only travel inside the mesh, its body stops overlapping walls. A good value is slightly larger than the character's collision radius. If agents can't fit through narrow corridors, suspect that this value is too large.

Tip: If your characters vary in size, prepare separate NavigationPolygon resources per size and bake each with its own agent_radius.

Handling Moving Obstacles with NavigationObstacle2D

A baked mesh is static. Obstacles that appear or move later, like a crate the player drops or a sliding door, are not baked into it. To make agents avoid those, add a NavigationObstacle2D to the obstacle.

Top-down view showing a NavigationObstacle2D on a moving obstacle creating a dotted avoidance circle, causing the agent to curve around instead of going straight

NavigationObstacle2D creates a temporary avoidance area around itself without rebaking the mesh. Agents passing nearby adjust their paths to steer clear. Rebaking is expensive, so letting moving objects handle avoidance this way is the standard approach (each obstacle does cost performance, so keep the count to what you actually need).

Which objects count as obstacles also depends on your collision layer and mask settings. If something isn't being avoided when it should be, check the layers too.

Sponsored

Common Mistakes and Best Practices

Common mistakeBest practice
Baking fails because obstacle collision is open or too complexUse closed, simple shapes. For TileMaps, set source_geometry_mode to the group method and add them to the target group
Leaving agent_radius at 0 so characters clip into wallsSet it slightly larger than the character radius so the mesh shrinks inward
Moving obstacles aren't avoidedAdd a NavigationObstacle2D and check the collision layers/masks
Rebaking every time an obstacle changesBake only static terrain and leave moving things to NavigationObstacle2D

Bonus: Good to Know for Later

  • Walking on this map: once the mesh exists, use NavigationAgent2D to move characters by "set a destination, then move to the next waypoint." All the chase and patrol code lives there.
  • 3D works the same way: NavigationRegion3D plus NavigationMesh follows the exact same "bake a map" flow in 3D.
  • AI decisions are a separate layer: a navmesh handles how to walk (the route). When to chase or patrol (the decision) belongs to state machines or behavior trees, which you combine with pathfinding.

Summary

  • A navigation mesh is a map for AI. Unlike physics, it lets agents avoid obstacles before touching them
  • Give a NavigationRegion2D a NavigationPolygon and use Bake to generate the walkable area
  • agent_radius shrinks the mesh inward from walls so characters don't clip into them
  • Handle moving obstacles with NavigationObstacle2D instead of rebaking

Start with a stage that has a few walls, bake a NavigationRegion2D, and check that the blue polygon correctly covers the walkable area. Once the map is ready, move on to NavigationAgent2D and actually walk on it.

Further Reading