:github_url: hide .. Generated automatically by doc/tools/make_rst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the Navigation2D.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_Navigation2D: Navigation2D ============ **Inherits:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` 2D navigation and pathfinding node. Description ----------- Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of :ref:`NavigationPolygon` resources. By default, these are automatically collected from child :ref:`NavigationPolygonInstance` nodes, but they can also be added on the fly with :ref:`navpoly_add`. **Note:** The current navigation system has many known issues and will not always return optimal paths as expected. These issues will be fixed in Godot 4.0. Tutorials --------- - `2D Navigation Demo `__ Methods ------- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_closest_point` **(** :ref:`Vector2` to_point **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` | :ref:`get_closest_point_owner` **(** :ref:`Vector2` to_point **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PoolVector2Array` | :ref:`get_simple_path` **(** :ref:`Vector2` start, :ref:`Vector2` end, :ref:`bool` optimize=true **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`navpoly_add` **(** :ref:`NavigationPolygon` mesh, :ref:`Transform2D` xform, :ref:`Object` owner=null **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`navpoly_remove` **(** :ref:`int` id **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`navpoly_set_transform` **(** :ref:`int` id, :ref:`Transform2D` xform **)** | +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Method Descriptions ------------------- .. _class_Navigation2D_method_get_closest_point: - :ref:`Vector2` **get_closest_point** **(** :ref:`Vector2` to_point **)** Returns the navigation point closest to the point given. Points are in local coordinate space. ---- .. _class_Navigation2D_method_get_closest_point_owner: - :ref:`Object` **get_closest_point_owner** **(** :ref:`Vector2` to_point **)** Returns the owner of the :ref:`NavigationPolygon` which contains the navigation point closest to the point given. This is usually a :ref:`NavigationPolygonInstance`. For polygons added via :ref:`navpoly_add`, returns the owner that was given (or ``null`` if the ``owner`` parameter was omitted). ---- .. _class_Navigation2D_method_get_simple_path: - :ref:`PoolVector2Array` **get_simple_path** **(** :ref:`Vector2` start, :ref:`Vector2` end, :ref:`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. **Note:** This method has known issues and will often return non-optimal paths. These issues will be fixed in Godot 4.0. ---- .. _class_Navigation2D_method_navpoly_add: - :ref:`int` **navpoly_add** **(** :ref:`NavigationPolygon` mesh, :ref:`Transform2D` xform, :ref:`Object` owner=null **)** Adds a :ref:`NavigationPolygon`. Returns an ID for use with :ref:`navpoly_remove` or :ref:`navpoly_set_transform`. If given, a :ref:`Transform2D` is applied to the polygon. The optional ``owner`` is used as return value for :ref:`get_closest_point_owner`. ---- .. _class_Navigation2D_method_navpoly_remove: - void **navpoly_remove** **(** :ref:`int` id **)** Removes the :ref:`NavigationPolygon` with the given ID. ---- .. _class_Navigation2D_method_navpoly_set_transform: - void **navpoly_set_transform** **(** :ref:`int` id, :ref:`Transform2D` xform **)** Sets the transform applied to the :ref:`NavigationPolygon` with the given ID. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`