Class reference

NavigationPolygon

Inherits Resource

Experimental.

A 2D navigation mesh that describes a traversable surface for pathfinding.

Description

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_mesh
		
		var newNavigationMesh = new NavigationPolygon();
		Vector2[] boundingOutline = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
		newNavigationMesh.AddOutline(boundingOutline);
		NavigationServer2D.BakeFromSourceGeometryData(newNavigationMesh, new NavigationMeshSourceGeometryData2D());
		GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
		

Adding 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_mesh
		
		var newNavigationMesh = new NavigationPolygon();
		Vector2[] newVertices = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
		newNavigationMesh.Vertices = newVertices;
		int[] newPolygonIndices = [0, 1, 2, 3];
		newNavigationMesh.AddPolygon(newPolygonIndices);
		GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
		

Properties

float agent_radius = 10.0

The 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.

Rect2 baking_rect = Rect2(0, 0, 0, 0)

If the baking Rect2 has an area the navigation mesh baking will be restricted to its enclosing area.

float border_size = 0.0

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.

float cell_size = 1.0

The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.

int parsed_geometry_type = 2

Determines which type of nodes will be parsed as geometry.

int sample_partition_type = 0

Partitioning algorithm for creating the navigation mesh polys.

int source_geometry_mode = 0

The source of the geometry used when baking.

Methods

void add_outline_at_index(PackedVector2Array outline, int index)

Adds a PackedVector2Array that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.

void clear()

Clears the internal arrays for vertices and polygon indices.

void clear_outlines()

Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.

void clear_polygons()

Clears the array of polygons, but it doesn't clear the array of outlines and vertices.

int get_outline_count() const

Returns the number of outlines that were created in the editor or by script.

bool get_parsed_collision_mask_value(int layer_number) const

Returns whether or not the specified layer of the parsed_collision_mask is enabled, given a layer_number between 1 and 32.

int get_polygon_count() const

Returns the count of all polygons.

void set_parsed_collision_mask_value(int layer_number, bool value)

Based on value, enables or disables the specified layer in the parsed_collision_mask, given a layer_number between 1 and 32.

Constants

SAMPLE_PARTITION_CONVEX_PARTITION = 0

Enum: SamplePartitionType

Convex partitioning that yields navigation mesh with convex polygons.

SAMPLE_PARTITION_TRIANGULATE = 1

Enum: SamplePartitionType

Triangulation partitioning that yields navigation mesh with triangle polygons.

SAMPLE_PARTITION_MAX = 2

Enum: SamplePartitionType

Represents the size of the SamplePartitionType enum.

PARSED_GEOMETRY_MESH_INSTANCES = 0

Enum: ParsedGeometryType

Parses 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 = 1

Enum: ParsedGeometryType

Parses StaticBody2D and TileMap colliders as obstruction geometry. The collider should be in any of the layers specified by parsed_collision_mask.

PARSED_GEOMETRY_MAX = 3

Enum: ParsedGeometryType

Represents the size of the ParsedGeometryType enum.

SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0

Enum: SourceGeometryMode

Scans the child nodes of the root node recursively for geometry.

SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1

Enum: SourceGeometryMode

Scans nodes in a group and their child nodes recursively for geometry. The group is specified by source_geometry_group_name.

SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2

Enum: SourceGeometryMode

Uses nodes in a group for geometry. The group is specified by source_geometry_group_name.

SOURCE_GEOMETRY_MAX = 3

Enum: SourceGeometryMode

Represents the size of the SourceGeometryMode enum.

Tutorials

Source revision 5592dc3a7a61
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.