123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- :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/<name>/doc_classes.
- .. _class_Navigation2D:
- Navigation2D
- ============
- **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
- 2D navigation and pathfinding node.
- Description
- -----------
- Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of :ref:`NavigationPolygon<class_NavigationPolygon>` resources. By default, these are automatically collected from child :ref:`NavigationPolygonInstance<class_NavigationPolygonInstance>` nodes, but they can also be added on the fly with :ref:`navpoly_add<class_Navigation2D_method_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 <https://godotengine.org/asset-library/asset/117>`__
- Methods
- -------
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_closest_point<class_Navigation2D_method_get_closest_point>` **(** :ref:`Vector2<class_Vector2>` to_point **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Object<class_Object>` | :ref:`get_closest_point_owner<class_Navigation2D_method_get_closest_point_owner>` **(** :ref:`Vector2<class_Vector2>` to_point **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolVector2Array<class_PoolVector2Array>` | :ref:`get_simple_path<class_Navigation2D_method_get_simple_path>` **(** :ref:`Vector2<class_Vector2>` start, :ref:`Vector2<class_Vector2>` end, :ref:`bool<class_bool>` optimize=true **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`navpoly_add<class_Navigation2D_method_navpoly_add>` **(** :ref:`NavigationPolygon<class_NavigationPolygon>` mesh, :ref:`Transform2D<class_Transform2D>` xform, :ref:`Object<class_Object>` owner=null **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`navpoly_remove<class_Navigation2D_method_navpoly_remove>` **(** :ref:`int<class_int>` id **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`navpoly_set_transform<class_Navigation2D_method_navpoly_set_transform>` **(** :ref:`int<class_int>` id, :ref:`Transform2D<class_Transform2D>` xform **)** |
- +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Method Descriptions
- -------------------
- .. _class_Navigation2D_method_get_closest_point:
- - :ref:`Vector2<class_Vector2>` **get_closest_point** **(** :ref:`Vector2<class_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<class_Object>` **get_closest_point_owner** **(** :ref:`Vector2<class_Vector2>` to_point **)**
- Returns the owner of the :ref:`NavigationPolygon<class_NavigationPolygon>` which contains the navigation point closest to the point given. This is usually a :ref:`NavigationPolygonInstance<class_NavigationPolygonInstance>`. For polygons added via :ref:`navpoly_add<class_Navigation2D_method_navpoly_add>`, returns the owner that was given (or ``null`` if the ``owner`` parameter was omitted).
- ----
- .. _class_Navigation2D_method_get_simple_path:
- - :ref:`PoolVector2Array<class_PoolVector2Array>` **get_simple_path** **(** :ref:`Vector2<class_Vector2>` start, :ref:`Vector2<class_Vector2>` end, :ref:`bool<class_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<class_int>` **navpoly_add** **(** :ref:`NavigationPolygon<class_NavigationPolygon>` mesh, :ref:`Transform2D<class_Transform2D>` xform, :ref:`Object<class_Object>` owner=null **)**
- Adds a :ref:`NavigationPolygon<class_NavigationPolygon>`. Returns an ID for use with :ref:`navpoly_remove<class_Navigation2D_method_navpoly_remove>` or :ref:`navpoly_set_transform<class_Navigation2D_method_navpoly_set_transform>`. If given, a :ref:`Transform2D<class_Transform2D>` is applied to the polygon. The optional ``owner`` is used as return value for :ref:`get_closest_point_owner<class_Navigation2D_method_get_closest_point_owner>`.
- ----
- .. _class_Navigation2D_method_navpoly_remove:
- - void **navpoly_remove** **(** :ref:`int<class_int>` id **)**
- Removes the :ref:`NavigationPolygon<class_NavigationPolygon>` with the given ID.
- ----
- .. _class_Navigation2D_method_navpoly_set_transform:
- - void **navpoly_set_transform** **(** :ref:`int<class_int>` id, :ref:`Transform2D<class_Transform2D>` xform **)**
- Sets the transform applied to the :ref:`NavigationPolygon<class_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.)`
|