Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
NavigationPolygon¶
Inherits: Resource < RefCounted < Object
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();
var boundingOutline = new Vector2[] { 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();
var newVertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
newNavigationMesh.Vertices = newVertices;
var newPolygonIndices = new int[] { 0, 1, 2, 3 };
newNavigationMesh.AddPolygon(newPolygonIndices);
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
add_outline ( PackedVector2Array outline ) |
void |
add_outline_at_index ( PackedVector2Array outline, int index ) |
void |
add_polygon ( PackedInt32Array polygon ) |
void |
clear ( ) |
void |
clear_outlines ( ) |
void |
clear_polygons ( ) |
get_outline ( int idx ) const |
|
get_outline_count ( ) const |
|
get_parsed_collision_mask_value ( int layer_number ) const |
|
get_polygon ( int idx ) |
|
get_polygon_count ( ) const |
|
get_vertices ( ) const |
|
void |
|
void |
remove_outline ( int idx ) |
void |
set_outline ( int idx, PackedVector2Array outline ) |
void |
set_parsed_collision_mask_value ( int layer_number, bool value ) |
void |
set_vertices ( PackedVector2Array vertices ) |
Enumerations¶
enum ParsedGeometryType:
ParsedGeometryType PARSED_GEOMETRY_MESH_INSTANCES = 0
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.
ParsedGeometryType PARSED_GEOMETRY_STATIC_COLLIDERS = 1
Parses StaticBody2D and TileMap colliders as obstruction geometry. The collider should be in any of the layers specified by parsed_collision_mask.
ParsedGeometryType PARSED_GEOMETRY_BOTH = 2
Both PARSED_GEOMETRY_MESH_INSTANCES and PARSED_GEOMETRY_STATIC_COLLIDERS.
ParsedGeometryType PARSED_GEOMETRY_MAX = 3
Represents the size of the ParsedGeometryType enum.
enum SourceGeometryMode:
SourceGeometryMode SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0
Scans the child nodes of the root node recursively for geometry.
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1
Scans nodes in a group and their child nodes recursively for geometry. The group is specified by source_geometry_group_name.
SourceGeometryMode SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2
Uses nodes in a group for geometry. The group is specified by source_geometry_group_name.
SourceGeometryMode SOURCE_GEOMETRY_MAX = 3
Represents the size of the SourceGeometryMode enum.
Property Descriptions¶
float agent_radius = 10.0
The distance to erode/shrink the walkable surface when baking the navigation mesh.
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_collision_mask = 4294967295
The physics layers to scan for static colliders.
Only used when parsed_geometry_type is PARSED_GEOMETRY_STATIC_COLLIDERS or PARSED_GEOMETRY_BOTH.
ParsedGeometryType parsed_geometry_type = 2
void set_parsed_geometry_type ( ParsedGeometryType value )
ParsedGeometryType get_parsed_geometry_type ( )
Determines which type of nodes will be parsed as geometry. See ParsedGeometryType for possible values.
StringName source_geometry_group_name = &"navigation_polygon_source_geometry_group"
void set_sour