class_navigationagent2d.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 NavigationAgent2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_NavigationAgent2D:
  6. NavigationAgent2D
  7. =================
  8. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. 2D Agent used in navigation for collision avoidance.
  10. Description
  11. -----------
  12. 2D Agent that is used in navigation to reach a location while avoiding static and dynamic obstacles. The dynamic obstacles are avoided using RVO collision avoidance. The agent needs navigation data to work correctly. ``NavigationAgent2D`` is physics safe.
  13. Properties
  14. ----------
  15. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  16. | :ref:`int<class_int>` | :ref:`max_neighbors<class_NavigationAgent2D_property_max_neighbors>` | ``10`` |
  17. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  18. | :ref:`float<class_float>` | :ref:`max_speed<class_NavigationAgent2D_property_max_speed>` | ``200.0`` |
  19. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  20. | :ref:`float<class_float>` | :ref:`neighbor_dist<class_NavigationAgent2D_property_neighbor_dist>` | ``500.0`` |
  21. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  22. | :ref:`float<class_float>` | :ref:`path_max_distance<class_NavigationAgent2D_property_path_max_distance>` | ``3.0`` |
  23. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  24. | :ref:`float<class_float>` | :ref:`radius<class_NavigationAgent2D_property_radius>` | ``10.0`` |
  25. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  26. | :ref:`float<class_float>` | :ref:`target_desired_distance<class_NavigationAgent2D_property_target_desired_distance>` | ``1.0`` |
  27. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  28. | :ref:`float<class_float>` | :ref:`time_horizon<class_NavigationAgent2D_property_time_horizon>` | ``20.0`` |
  29. +---------------------------+------------------------------------------------------------------------------------------+-----------+
  30. Methods
  31. -------
  32. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`distance_to_target<class_NavigationAgent2D_method_distance_to_target>` **(** **)** |const| |
  34. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector2<class_Vector2>` | :ref:`get_final_location<class_NavigationAgent2D_method_get_final_location>` **(** **)** |
  36. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_nav_path<class_NavigationAgent2D_method_get_nav_path>` **(** **)** |const| |
  38. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`get_nav_path_index<class_NavigationAgent2D_method_get_nav_path_index>` **(** **)** |const| |
  40. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`get_next_location<class_NavigationAgent2D_method_get_next_location>` **(** **)** |
  42. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`RID<class_RID>` | :ref:`get_rid<class_NavigationAgent2D_method_get_rid>` **(** **)** |const| |
  44. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_Vector2>` | :ref:`get_target_location<class_NavigationAgent2D_method_get_target_location>` **(** **)** |const| |
  46. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_navigation_finished<class_NavigationAgent2D_method_is_navigation_finished>` **(** **)** |
  48. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_target_reachable<class_NavigationAgent2D_method_is_target_reachable>` **(** **)** |
  50. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`is_target_reached<class_NavigationAgent2D_method_is_target_reached>` **(** **)** |const| |
  52. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_target_location<class_NavigationAgent2D_method_set_target_location>` **(** :ref:`Vector2<class_Vector2>` location **)** |
  54. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_velocity<class_NavigationAgent2D_method_set_velocity>` **(** :ref:`Vector2<class_Vector2>` velocity **)** |
  56. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  57. Signals
  58. -------
  59. .. _class_NavigationAgent2D_signal_navigation_finished:
  60. - **navigation_finished** **(** **)**
  61. Notifies when the final location is reached.
  62. ----
  63. .. _class_NavigationAgent2D_signal_path_changed:
  64. - **path_changed** **(** **)**
  65. Notifies when the navigation path changes.
  66. ----
  67. .. _class_NavigationAgent2D_signal_target_reached:
  68. - **target_reached** **(** **)**
  69. Notifies when the player defined target, set with :ref:`set_target_location<class_NavigationAgent2D_method_set_target_location>`, is reached.
  70. ----
  71. .. _class_NavigationAgent2D_signal_velocity_computed:
  72. - **velocity_computed** **(** :ref:`Vector3<class_Vector3>` safe_velocity **)**
  73. Notifies when the collision avoidance velocity is calculated. Emitted by :ref:`set_velocity<class_NavigationAgent2D_method_set_velocity>`.
  74. Property Descriptions
  75. ---------------------
  76. .. _class_NavigationAgent2D_property_max_neighbors:
  77. - :ref:`int<class_int>` **max_neighbors**
  78. +-----------+--------------------------+
  79. | *Default* | ``10`` |
  80. +-----------+--------------------------+
  81. | *Setter* | set_max_neighbors(value) |
  82. +-----------+--------------------------+
  83. | *Getter* | get_max_neighbors() |
  84. +-----------+--------------------------+
  85. The maximum number of neighbors for the agent to consider.
  86. ----
  87. .. _class_NavigationAgent2D_property_max_speed:
  88. - :ref:`float<class_float>` **max_speed**
  89. +-----------+----------------------+
  90. | *Default* | ``200.0`` |
  91. +-----------+----------------------+
  92. | *Setter* | set_max_speed(value) |
  93. +-----------+----------------------+
  94. | *Getter* | get_max_speed() |
  95. +-----------+----------------------+
  96. The maximum speed that an agent can move.
  97. ----
  98. .. _class_NavigationAgent2D_property_neighbor_dist:
  99. - :ref:`float<class_float>` **neighbor_dist**
  100. +-----------+--------------------------+
  101. | *Default* | ``500.0`` |
  102. +-----------+--------------------------+
  103. | *Setter* | set_neighbor_dist(value) |
  104. +-----------+--------------------------+
  105. | *Getter* | get_neighbor_dist() |
  106. +-----------+--------------------------+
  107. The distance to search for other agents.
  108. ----
  109. .. _class_NavigationAgent2D_property_path_max_distance:
  110. - :ref:`float<class_float>` **path_max_distance**
  111. +-----------+------------------------------+
  112. | *Default* | ``3.0`` |
  113. +-----------+------------------------------+
  114. | *Setter* | set_path_max_distance(value) |
  115. +-----------+------------------------------+
  116. | *Getter* | get_path_max_distance() |
  117. +-----------+------------------------------+
  118. The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path.
  119. ----
  120. .. _class_NavigationAgent2D_property_radius:
  121. - :ref:`float<class_float>` **radius**
  122. +-----------+-------------------+
  123. | *Default* | ``10.0`` |
  124. +-----------+-------------------+
  125. | *Setter* | set_radius(value) |
  126. +-----------+-------------------+
  127. | *Getter* | get_radius() |
  128. +-----------+-------------------+
  129. The radius of the agent.
  130. ----
  131. .. _class_NavigationAgent2D_property_target_desired_distance:
  132. - :ref:`float<class_float>` **target_desired_distance**
  133. +-----------+------------------------------------+
  134. | *Default* | ``1.0`` |
  135. +-----------+------------------------------------+
  136. | *Setter* | set_target_desired_distance(value) |
  137. +-----------+------------------------------------+
  138. | *Getter* | get_target_desired_distance() |
  139. +-----------+------------------------------------+
  140. The distance threshold before a target is considered to be reached. This will allow an agent to not have to hit a point on the path exactly, but in the area.
  141. ----
  142. .. _class_NavigationAgent2D_property_time_horizon:
  143. - :ref:`float<class_float>` **time_horizon**
  144. +-----------+-------------------------+
  145. | *Default* | ``20.0`` |
  146. +-----------+-------------------------+
  147. | *Setter* | set_time_horizon(value) |
  148. +-----------+-------------------------+
  149. | *Getter* | get_time_horizon() |
  150. +-----------+-------------------------+
  151. The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithm, are safe with respect to other agents. The larger the number, the sooner the agent will respond to other agents, but less freedom in choosing its velocities. Must be positive.
  152. Method Descriptions
  153. -------------------
  154. .. _class_NavigationAgent2D_method_distance_to_target:
  155. - :ref:`float<class_float>` **distance_to_target** **(** **)** |const|
  156. Returns the distance to the target location, using the agent's global position. The user must set the target location with :ref:`set_target_location<class_NavigationAgent2D_method_set_target_location>` in order for this to be accurate.
  157. ----
  158. .. _class_NavigationAgent2D_method_get_final_location:
  159. - :ref:`Vector2<class_Vector2>` **get_final_location** **(** **)**
  160. Returns the reachable final location in global coordinates. This can change if the navigation path is altered in any way. Because of this, it would be best to check this each frame.
  161. ----
  162. .. _class_NavigationAgent2D_method_get_nav_path:
  163. - :ref:`PackedVector2Array<class_PackedVector2Array>` **get_nav_path** **(** **)** |const|
  164. Returns the path from start to finish in global coordinates.
  165. ----
  166. .. _class_NavigationAgent2D_method_get_nav_path_index:
  167. - :ref:`int<class_int>` **get_nav_path_index** **(** **)** |const|
  168. Returns which index the agent is currently on in the navigation path's :ref:`PackedVector2Array<class_PackedVector2Array>`.
  169. ----
  170. .. _class_NavigationAgent2D_method_get_next_location:
  171. - :ref:`Vector2<class_Vector2>` **get_next_location** **(** **)**
  172. Returns a :ref:`Vector2<class_Vector2>` in global coordinates, that can be moved to, making sure that there are no static objects in the way. If the agent does not have a navigation path, it will return the position of the agent's parent.
  173. ----
  174. .. _class_NavigationAgent2D_method_get_rid:
  175. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  176. ----
  177. .. _class_NavigationAgent2D_method_get_target_location:
  178. - :ref:`Vector2<class_Vector2>` **get_target_location** **(** **)** |const|
  179. Returns the user defined :ref:`Vector2<class_Vector2>` after setting the target location.
  180. ----
  181. .. _class_NavigationAgent2D_method_is_navigation_finished:
  182. - :ref:`bool<class_bool>` **is_navigation_finished** **(** **)**
  183. Returns true if the navigation path's final location has been reached.
  184. ----
  185. .. _class_NavigationAgent2D_method_is_target_reachable:
  186. - :ref:`bool<class_bool>` **is_target_reachable** **(** **)**
  187. Returns true if the target location is reachable. The target location is set using :ref:`set_target_location<class_NavigationAgent2D_method_set_target_location>`.
  188. ----
  189. .. _class_NavigationAgent2D_method_is_target_reached:
  190. - :ref:`bool<class_bool>` **is_target_reached** **(** **)** |const|
  191. Returns true if the target location is reached. The target location is set using :ref:`set_target_location<class_NavigationAgent2D_method_set_target_location>`. It may not always be possible to reach the target location. It should always be possible to reach the final location though. See :ref:`get_final_location<class_NavigationAgent2D_method_get_final_location>`.
  192. ----
  193. .. _class_NavigationAgent2D_method_set_target_location:
  194. - void **set_target_location** **(** :ref:`Vector2<class_Vector2>` location **)**
  195. Sets the user desired final location. This will clear the current navigation path.
  196. ----
  197. .. _class_NavigationAgent2D_method_set_velocity:
  198. - void **set_velocity** **(** :ref:`Vector2<class_Vector2>` velocity **)**
  199. Sends the passed in velocity to the collision avoidance algorithm. It will adjust the velocity to avoid collisions. Once the adjustment to the velocity is complete, it will emit the :ref:`velocity_computed<class_NavigationAgent2D_signal_velocity_computed>` signal.
  200. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  201. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  202. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  203. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  204. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  205. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`