NavigationPolygon¶
Inherits: Resource < RefCounted < Object
A navigation polygon that defines traversable areas and obstacles.
Description¶
There are two ways to create polygons. Either by using the add_outline method, or using the add_polygon method.
Using add_outline:
var polygon = NavigationPolygon.new()
var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.add_outline(outline)
polygon.make_polygons_from_outlines()
$NavigationRegion2D.navigation_polygon = polygon
var polygon = new NavigationPolygon();
var outline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
polygon.AddOutline(outline);
polygon.MakePolygonsFromOutlines();
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = polygon;
Using add_polygon and indices of the vertices array.
var polygon = NavigationPolygon.new()
var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.vertices = vertices
var indices = PackedInt32Array([0, 1, 2, 3])
polygon.add_polygon(indices)
$NavigationRegion2D.navigation_polygon = polygon
var polygon = new NavigationPolygon();
var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
polygon.Vertices = vertices;
var indices = new int[] { 0, 1, 2, 3 };
polygon.AddPolygon(indices);
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = polygon;
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 |
|