A 2D navigation mesh that describes a traversable surface for pathfinding.
A navigation mesh can be created either by baking it with the help of the NavigationServer2D, or by adding vertices and convex polygon indices arrays manually.
To bake a navigation mesh at least one outline needs to be added that defines the outer bounds of the baked area.
var new_navigation_mesh = NavigationPolygon.new()
var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.add_outline(bounding_outline)
NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());
$NavigationRegion2D.navigation_polygon = new_navigation_meshAdding vertices and polygon indices manually.
var new_navigation_mesh = NavigationPolygon.new()
var new_vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.vertices = new_vertices
var new_polygon_indices = PackedInt32Array([0, 1, 2, 3])
new_navigation_mesh.add_polygon(new_polygon_indices)
$NavigationRegion2D.navigation_polygon = new_navigation_meshThe distance to erode/shrink the walkable surface when baking the navigation mesh.
Note: The radius must be equal or higher than 0.0. If the radius is 0.0, it won't be possible to fix invalid outline overlaps and other precision errors during the baking process. As a result, some obstacles may be excluded incorrectly from the final navigation mesh, or may delete the navigation mesh's polygons.
If the baking Rect2 has an area the navigation mesh baking will be restricted to its enclosing area.
The position offset applied to the baking_rect Rect2.
The size of the non-navigable border around the bake bounding area defined by the baking_rect Rect2.
In conjunction with the baking_rect the border size can be used to bake tile aligned navigation meshes without the tile edges being shrunk by agent_radius.
The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.
The physics layers to scan for static colliders.
Only used when parsed_geometry_type is PARSED_GEOMETRY_STATIC_COLLIDERS or PARSED_GEOMETRY_BOTH.
The group name of nodes that should be parsed for baking source geometry.
Only used when source_geometry_mode is SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN or SOURCE_GEOMETRY_GROUPS_EXPLICIT.
Appends a PackedVector2Array that contains the vertices of an outline to the internal array that contains all the outlines.
Adds a PackedVector2Array that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.
Adds a polygon using the indices of the vertices you get when calling get_vertices().
Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
Returns a PackedVector2Array containing the vertices of an outline that was created in the editor or by script.
Returns whether or not the specified layer of the parsed_collision_mask is enabled, given a layer_number between 1 and 32.
Returns a PackedInt32Array containing the indices of the vertices of a created polygon.
Returns a PackedVector2Array containing all the vertices being used to create the polygons.
Creates polygons from the outlines added in the editor or by script.
Removes an outline created in the editor or by script. You have to call make_polygons_from_outlines() for the polygons to update.
Changes an outline created in the editor or by script. You have to call make_polygons_from_outlines() for the polygons to update.
Based on value, enables or disables the specified layer in the parsed_collision_mask, given a layer_number between 1 and 32.
Sets the vertices that can be then indexed to create polygons with the add_polygon() method.
SAMPLE_PARTITION_CONVEX_PARTITION = 0Convex partitioning that results in a navigation mesh with convex polygons.
SAMPLE_PARTITION_TRIANGULATE = 1Triangulation partitioning that results in a navigation mesh with triangle polygons.
SAMPLE_PARTITION_MAX = 2Represents the size of the SamplePartitionType enum.
PARSED_GEOMETRY_MESH_INSTANCES = 0Parses mesh instances as obstruction geometry. This includes Polygon2D, MeshInstance2D, MultiMeshInstance2D, and TileMap nodes.
Meshes are only parsed when they use a 2D vertices surface format.
PARSED_GEOMETRY_STATIC_COLLIDERS = 1Parses StaticBody2D and TileMap colliders as obstruction geometry. The collider should be in any of the layers specified by parsed_collision_mask.
PARSED_GEOMETRY_BOTH = 2Both PARSED_GEOMETRY_MESH_INSTANCES and PARSED_GEOMETRY_STATIC_COLLIDERS.
PARSED_GEOMETRY_MAX = 3Represents the size of the ParsedGeometryType enum.
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0Scans the child nodes of the root node recursively for geometry.
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1Scans nodes in a group and their child nodes recursively for geometry. The group is specified by source_geometry_group_name.
SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2Uses nodes in a group for geometry. The group is specified by source_geometry_group_name.
SOURCE_GEOMETRY_MAX = 3Represents the size of the SourceGeometryMode enum.