Navigation2D¶
Inherits: Node2D < CanvasItem < Node < Object
2D navigation and pathfinding node.
Description¶
Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of NavigationPolygon resources. By default, these are automatically collected from child NavigationPolygonInstance nodes, but they can also be added on the fly with navpoly_add.
Methods¶
Vector2 | get_closest_point ( Vector2 to_point ) |
Object | get_closest_point_owner ( Vector2 to_point ) |
PoolVector2Array | get_simple_path ( Vector2 start, Vector2 end, bool optimize=true ) |
int | navpoly_add ( NavigationPolygon mesh, Transform2D xform, Object owner=null ) |
void | navpoly_remove ( int id ) |
void | navpoly_set_transform ( int id, Transform2D xform ) |
Method Descriptions¶
Returns the navigation point closest to the point given. Points are in local coordinate space.
Returns the owner of the NavigationPolygon which contains the navigation point closest to the point given. This is usually a NavigationPolygonInstance. For polygons added via navpoly_add, returns the owner that was given (or null
if the owner
parameter was omitted).
- PoolVector2Array get_simple_path ( Vector2 start, Vector2 end, bool optimize=true )
Returns the path between two given points. Points are in local coordinate space. If optimize
is true
(the default), the path is smoothed by merging path segments where possible.
- int navpoly_add ( NavigationPolygon mesh, Transform2D xform, Object owner=null )
Adds a NavigationPolygon. Returns an ID for use with navpoly_remove or navpoly_set_transform. If given, a Transform2D is applied to the polygon. The optional owner
is used as return value for get_closest_point_owner.
- void navpoly_remove ( int id )
Removes the NavigationPolygon with the given ID.
- void navpoly_set_transform ( int id, Transform2D xform )
Sets the transform applied to the NavigationPolygon with the given ID.