class_navigation2d.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Navigation2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Navigation2D:
  6. Navigation2D
  7. ============
  8. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. 2D navigation and pathfinding node.
  10. Description
  11. -----------
  12. 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>`.
  13. **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.
  14. Tutorials
  15. ---------
  16. - `2D Navigation Demo <https://godotengine.org/asset-library/asset/117>`__
  17. Methods
  18. -------
  19. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Vector2<class_Vector2>` | :ref:`get_closest_point<class_Navigation2D_method_get_closest_point>` **(** :ref:`Vector2<class_Vector2>` to_point **)** |
  21. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Object<class_Object>` | :ref:`get_closest_point_owner<class_Navigation2D_method_get_closest_point_owner>` **(** :ref:`Vector2<class_Vector2>` to_point **)** |
  23. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :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 **)** |
  25. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :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 **)** |
  27. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`navpoly_remove<class_Navigation2D_method_navpoly_remove>` **(** :ref:`int<class_int>` id **)** |
  29. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`navpoly_set_transform<class_Navigation2D_method_navpoly_set_transform>` **(** :ref:`int<class_int>` id, :ref:`Transform2D<class_Transform2D>` xform **)** |
  31. +-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. Method Descriptions
  33. -------------------
  34. .. _class_Navigation2D_method_get_closest_point:
  35. - :ref:`Vector2<class_Vector2>` **get_closest_point** **(** :ref:`Vector2<class_Vector2>` to_point **)**
  36. Returns the navigation point closest to the point given. Points are in local coordinate space.
  37. ----
  38. .. _class_Navigation2D_method_get_closest_point_owner:
  39. - :ref:`Object<class_Object>` **get_closest_point_owner** **(** :ref:`Vector2<class_Vector2>` to_point **)**
  40. 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).
  41. ----
  42. .. _class_Navigation2D_method_get_simple_path:
  43. - :ref:`PoolVector2Array<class_PoolVector2Array>` **get_simple_path** **(** :ref:`Vector2<class_Vector2>` start, :ref:`Vector2<class_Vector2>` end, :ref:`bool<class_bool>` optimize=true **)**
  44. 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.
  45. **Note:** This method has known issues and will often return non-optimal paths. These issues will be fixed in Godot 4.0.
  46. ----
  47. .. _class_Navigation2D_method_navpoly_add:
  48. - :ref:`int<class_int>` **navpoly_add** **(** :ref:`NavigationPolygon<class_NavigationPolygon>` mesh, :ref:`Transform2D<class_Transform2D>` xform, :ref:`Object<class_Object>` owner=null **)**
  49. 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>`.
  50. ----
  51. .. _class_Navigation2D_method_navpoly_remove:
  52. - void **navpoly_remove** **(** :ref:`int<class_int>` id **)**
  53. Removes the :ref:`NavigationPolygon<class_NavigationPolygon>` with the given ID.
  54. ----
  55. .. _class_Navigation2D_method_navpoly_set_transform:
  56. - void **navpoly_set_transform** **(** :ref:`int<class_int>` id, :ref:`Transform2D<class_Transform2D>` xform **)**
  57. Sets the transform applied to the :ref:`NavigationPolygon<class_NavigationPolygon>` with the given ID.
  58. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  59. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  60. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`