class_navigationagent2d.rst 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/NavigationAgent2D.xml.
  6. .. _class_NavigationAgent2D:
  7. NavigationAgent2D
  8. =================
  9. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. A 2D agent used to pathfind to a position while avoiding obstacles.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. A 2D agent used to pathfind to a position while avoiding static and dynamic obstacles. The calculation can be used by the parent node to dynamically move it along the path. Requires navigation data to work correctly.
  15. Dynamic obstacles are avoided using RVO collision avoidance. Avoidance is computed before physics, so the pathfinding information can be used safely in the physics step.
  16. \ **Note:** After setting the :ref:`target_position<class_NavigationAgent2D_property_target_position>` property, the :ref:`get_next_path_position<class_NavigationAgent2D_method_get_next_path_position>` method must be used once every physics frame to update the internal path logic of the navigation agent. The vector position it returns should be used as the next movement position for the agent's parent node.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Using NavigationAgents <../tutorials/navigation/navigation_using_navigationagents>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  27. | :ref:`bool<class_bool>` | :ref:`avoidance_enabled<class_NavigationAgent2D_property_avoidance_enabled>` | ``false`` |
  28. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  29. | :ref:`int<class_int>` | :ref:`avoidance_layers<class_NavigationAgent2D_property_avoidance_layers>` | ``1`` |
  30. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  31. | :ref:`int<class_int>` | :ref:`avoidance_mask<class_NavigationAgent2D_property_avoidance_mask>` | ``1`` |
  32. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  33. | :ref:`float<class_float>` | :ref:`avoidance_priority<class_NavigationAgent2D_property_avoidance_priority>` | ``1.0`` |
  34. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  35. | :ref:`bool<class_bool>` | :ref:`debug_enabled<class_NavigationAgent2D_property_debug_enabled>` | ``false`` |
  36. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  37. | :ref:`Color<class_Color>` | :ref:`debug_path_custom_color<class_NavigationAgent2D_property_debug_path_custom_color>` | ``Color(1, 1, 1, 1)`` |
  38. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  39. | :ref:`float<class_float>` | :ref:`debug_path_custom_line_width<class_NavigationAgent2D_property_debug_path_custom_line_width>` | ``-1.0`` |
  40. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  41. | :ref:`float<class_float>` | :ref:`debug_path_custom_point_size<class_NavigationAgent2D_property_debug_path_custom_point_size>` | ``4.0`` |
  42. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  43. | :ref:`bool<class_bool>` | :ref:`debug_use_custom<class_NavigationAgent2D_property_debug_use_custom>` | ``false`` |
  44. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  45. | :ref:`int<class_int>` | :ref:`max_neighbors<class_NavigationAgent2D_property_max_neighbors>` | ``10`` |
  46. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  47. | :ref:`float<class_float>` | :ref:`max_speed<class_NavigationAgent2D_property_max_speed>` | ``100.0`` |
  48. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  49. | :ref:`int<class_int>` | :ref:`navigation_layers<class_NavigationAgent2D_property_navigation_layers>` | ``1`` |
  50. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  51. | :ref:`float<class_float>` | :ref:`neighbor_distance<class_NavigationAgent2D_property_neighbor_distance>` | ``500.0`` |
  52. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  53. | :ref:`float<class_float>` | :ref:`path_desired_distance<class_NavigationAgent2D_property_path_desired_distance>` | ``20.0`` |
  54. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  55. | :ref:`float<class_float>` | :ref:`path_max_distance<class_NavigationAgent2D_property_path_max_distance>` | ``100.0`` |
  56. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  57. | :ref:`PathMetadataFlags<enum_NavigationPathQueryParameters2D_PathMetadataFlags>` | :ref:`path_metadata_flags<class_NavigationAgent2D_property_path_metadata_flags>` | ``7`` |
  58. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  59. | :ref:`PathPostProcessing<enum_NavigationPathQueryParameters2D_PathPostProcessing>` | :ref:`path_postprocessing<class_NavigationAgent2D_property_path_postprocessing>` | ``0`` |
  60. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  61. | :ref:`PathfindingAlgorithm<enum_NavigationPathQueryParameters2D_PathfindingAlgorithm>` | :ref:`pathfinding_algorithm<class_NavigationAgent2D_property_pathfinding_algorithm>` | ``0`` |
  62. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  63. | :ref:`float<class_float>` | :ref:`radius<class_NavigationAgent2D_property_radius>` | ``10.0`` |
  64. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  65. | :ref:`float<class_float>` | :ref:`target_desired_distance<class_NavigationAgent2D_property_target_desired_distance>` | ``10.0`` |
  66. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  67. | :ref:`Vector2<class_Vector2>` | :ref:`target_position<class_NavigationAgent2D_property_target_position>` | ``Vector2(0, 0)`` |
  68. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  69. | :ref:`float<class_float>` | :ref:`time_horizon_agents<class_NavigationAgent2D_property_time_horizon_agents>` | ``1.0`` |
  70. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  71. | :ref:`float<class_float>` | :ref:`time_horizon_obstacles<class_NavigationAgent2D_property_time_horizon_obstacles>` | ``0.0`` |
  72. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  73. | :ref:`Vector2<class_Vector2>` | :ref:`velocity<class_NavigationAgent2D_property_velocity>` | ``Vector2(0, 0)`` |
  74. +----------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------------------+
  75. .. rst-class:: classref-reftable-group
  76. Methods
  77. -------
  78. .. table::
  79. :widths: auto
  80. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`float<class_float>` | :ref:`distance_to_target<class_NavigationAgent2D_method_distance_to_target>` **(** **)** |const| |
  82. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`bool<class_bool>` | :ref:`get_avoidance_layer_value<class_NavigationAgent2D_method_get_avoidance_layer_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  84. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`bool<class_bool>` | :ref:`get_avoidance_mask_value<class_NavigationAgent2D_method_get_avoidance_mask_value>` **(** :ref:`int<class_int>` mask_number **)** |const| |
  86. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_current_navigation_path<class_NavigationAgent2D_method_get_current_navigation_path>` **(** **)** |const| |
  88. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`int<class_int>` | :ref:`get_current_navigation_path_index<class_NavigationAgent2D_method_get_current_navigation_path_index>` **(** **)** |const| |
  90. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`NavigationPathQueryResult2D<class_NavigationPathQueryResult2D>` | :ref:`get_current_navigation_result<class_NavigationAgent2D_method_get_current_navigation_result>` **(** **)** |const| |
  92. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Vector2<class_Vector2>` | :ref:`get_final_position<class_NavigationAgent2D_method_get_final_position>` **(** **)** |
  94. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`get_navigation_layer_value<class_NavigationAgent2D_method_get_navigation_layer_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
  96. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`RID<class_RID>` | :ref:`get_navigation_map<class_NavigationAgent2D_method_get_navigation_map>` **(** **)** |const| |
  98. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`Vector2<class_Vector2>` | :ref:`get_next_path_position<class_NavigationAgent2D_method_get_next_path_position>` **(** **)** |
  100. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`RID<class_RID>` | :ref:`get_rid<class_NavigationAgent2D_method_get_rid>` **(** **)** |const| |
  102. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`is_navigation_finished<class_NavigationAgent2D_method_is_navigation_finished>` **(** **)** |
  104. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`is_target_reachable<class_NavigationAgent2D_method_is_target_reachable>` **(** **)** |
  106. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`is_target_reached<class_NavigationAgent2D_method_is_target_reached>` **(** **)** |const| |
  108. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | void | :ref:`set_avoidance_layer_value<class_NavigationAgent2D_method_set_avoidance_layer_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  110. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | void | :ref:`set_avoidance_mask_value<class_NavigationAgent2D_method_set_avoidance_mask_value>` **(** :ref:`int<class_int>` mask_number, :ref:`bool<class_bool>` value **)** |
  112. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | void | :ref:`set_navigation_layer_value<class_NavigationAgent2D_method_set_navigation_layer_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
  114. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`set_navigation_map<class_NavigationAgent2D_method_set_navigation_map>` **(** :ref:`RID<class_RID>` navigation_map **)** |
  116. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`set_velocity_forced<class_NavigationAgent2D_method_set_velocity_forced>` **(** :ref:`Vector2<class_Vector2>` velocity **)** |
  118. +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. .. rst-class:: classref-section-separator
  120. ----
  121. .. rst-class:: classref-descriptions-group
  122. Signals
  123. -------
  124. .. _class_NavigationAgent2D_signal_link_reached:
  125. .. rst-class:: classref-signal
  126. **link_reached** **(** :ref:`Dictionary<class_Dictionary>` details **)**
  127. Notifies when a navigation link has been reached.
  128. The details dictionary may contain the following keys depending on the value of :ref:`path_metadata_flags<class_NavigationAgent2D_property_path_metadata_flags>`:
  129. - ``position``: The start position of the link that was reached.
  130. - ``type``: Always :ref:`NavigationPathQueryResult2D.PATH_SEGMENT_TYPE_LINK<class_NavigationPathQueryResult2D_constant_PATH_SEGMENT_TYPE_LINK>`.
  131. - ``rid``: The :ref:`RID<class_RID>` of the link.
  132. - ``owner``: The object which manages the link (usually :ref:`NavigationLink2D<class_NavigationLink2D>`).
  133. - ``link_entry_position``: If ``owner`` is available and the owner is a :ref:`NavigationLink2D<class_NavigationLink2D>`, it will contain the global position of the link's point the agent is entering.
  134. - ``link_exit_position``: If ``owner`` is available and the owner is a :ref:`NavigationLink2D<class_NavigationLink2D>`, it will contain the global position of the link's point which the agent is exiting.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_NavigationAgent2D_signal_navigation_finished:
  138. .. rst-class:: classref-signal
  139. **navigation_finished** **(** **)**
  140. Notifies when the final position is reached.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_NavigationAgent2D_signal_path_changed:
  144. .. rst-class:: classref-signal
  145. **path_changed** **(** **)**
  146. Notifies when the navigation path changes.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_NavigationAgent2D_signal_target_reached:
  150. .. rst-class:: classref-signal
  151. **target_reached** **(** **)**
  152. Notifies when the player-defined :ref:`target_position<class_NavigationAgent2D_property_target_position>` is reached.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_NavigationAgent2D_signal_velocity_computed:
  156. .. rst-class:: classref-signal
  157. **velocity_computed** **(** :ref:`Vector2<class_Vector2>` safe_velocity **)**
  158. Notifies when the collision avoidance velocity is calculated. Emitted when :ref:`velocity<class_NavigationAgent2D_property_velocity>` is set. Only emitted when :ref:`avoidance_enabled<class_NavigationAgent2D_property_avoidance_enabled>` is true.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_NavigationAgent2D_signal_waypoint_reached:
  162. .. rst-class:: classref-signal
  163. **waypoint_reached** **(** :ref:`Dictionary<class_Dictionary>` details **)**
  164. Notifies when a waypoint along the path has been reached.
  165. The details dictionary may contain the following keys depending on the value of :ref:`path_metadata_flags<class_NavigationAgent2D_property_path_metadata_flags>`:
  166. - ``position``: The position of the waypoint that was reached.
  167. - ``type``: The type of navigation primitive (region or link) that contains this waypoint.
  168. - ``rid``: The :ref:`RID<class_RID>` of the containing navigation primitive (region or link).
  169. - ``owner``: The object which manages the containing navigation primitive (region or link).
  170. .. rst-class:: classref-section-separator
  171. ----
  172. .. rst-class:: classref-descriptions-group
  173. Property Descriptions
  174. ---------------------
  175. .. _class_NavigationAgent2D_property_avoidance_enabled:
  176. .. rst-class:: classref-property
  177. :ref:`bool<class_bool>` **avoidance_enabled** = ``false``
  178. .. rst-class:: classref-property-setget
  179. - void **set_avoidance_enabled** **(** :ref:`bool<class_bool>` value **)**
  180. - :ref:`bool<class_bool>` **get_avoidance_enabled** **(** **)**
  181. If ``true`` the agent is registered for an RVO avoidance callback on the :ref:`NavigationServer2D<class_NavigationServer2D>`. When :ref:`velocity<class_NavigationAgent2D_property_velocity>` is used and the processing is completed a ``safe_velocity`` Vector2 is received with a signal connection to :ref:`velocity_computed<class_NavigationAgent2D_signal_velocity_computed>`. Avoidance processing with many registered agents has a significant performance cost and should only be enabled on agents that currently require it.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_NavigationAgent2D_property_avoidance_layers:
  185. .. rst-class:: classref-property
  186. :ref:`int<class_int>` **avoidance_layers** = ``1``
  187. .. rst-class:: classref-property-setget
  188. - void **set_avoidance_layers** **(** :ref:`int<class_int>` value **)**
  189. - :ref:`int<class_int>` **get_avoidance_layers** **(** **)**
  190. A bitfield determining the avoidance layers for this NavigationAgent. Other agents with a matching bit on the :ref:`avoidance_mask<class_NavigationAgent2D_property_avoidance_mask>` will avoid this agent.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_NavigationAgent2D_property_avoidance_mask:
  194. .. rst-class:: classref-property
  195. :ref:`int<class_int>` **avoidance_mask** = ``1``
  196. .. rst-class:: classref-property-setget
  197. - void **set_avoidance_mask** **(** :ref:`int<class_int>` value **)**
  198. - :ref:`int<class_int>` **get_avoidance_mask** **(** **)**
  199. A bitfield determining what other avoidance agents and obstacles this NavigationAgent will avoid when a bit matches at least one of their :ref:`avoidance_layers<class_NavigationAgent2D_property_avoidance_layers>`.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_NavigationAgent2D_property_avoidance_priority:
  203. .. rst-class:: classref-property
  204. :ref:`float<class_float>` **avoidance_priority** = ``1.0``
  205. .. rst-class:: classref-property-setget
  206. - void **set_avoidance_priority** **(** :ref:`float<class_float>` value **)**
  207. - :ref:`float<class_float>` **get_avoidance_priority** **(** **)**
  208. The agent does not adjust the velocity for other agents that would match the :ref:`avoidance_mask<class_NavigationAgent2D_property_avoidance_mask>` but have a lower :ref:`avoidance_priority<class_NavigationAgent2D_property_avoidance_priority>`. This in turn makes the other agents with lower priority adjust their velocities even more to avoid collision with this agent.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_NavigationAgent2D_property_debug_enabled:
  212. .. rst-class:: classref-property
  213. :ref:`bool<class_bool>` **debug_enabled** = ``false``
  214. .. rst-class:: classref-property-setget
  215. - void **set_debug_enabled** **(** :ref:`bool<class_bool>` value **)**
  216. - :ref:`bool<class_bool>` **get_debug_enabled** **(** **)**
  217. If ``true`` shows debug visuals for this agent.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_NavigationAgent2D_property_debug_path_custom_color:
  221. .. rst-class:: classref-property
  222. :ref:`Color<class_Color>` **debug_path_custom_color** = ``Color(1, 1, 1, 1)``
  223. .. rst-class:: classref-property-setget
  224. - void **set_debug_path_custom_color** **(** :ref:`Color<class_Color>` value **)**
  225. - :ref:`Color<class_Color>` **get_debug_path_custom_color** **(** **)**
  226. If :ref:`debug_use_custom<class_NavigationAgent2D_property_debug_use_custom>` is ``true`` uses this color for this agent instead of global color.
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_NavigationAgent2D_property_debug_path_custom_line_width:
  230. .. rst-class:: classref-property
  231. :ref:`float<class_float>` **debug_path_custom_line_width** = ``-1.0``
  232. .. rst-class:: classref-property-setget
  233. - void **set_debug_path_custom_line_width** **(** :ref:`float<class_float>` value **)**
  234. - :ref:`float<class_float>` **get_debug_path_custom_line_width** **(** **)**
  235. If :ref:`debug_use_custom<class_NavigationAgent2D_property_debug_use_custom>` is ``true`` uses this line width for rendering paths for this agent instead of global line width.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_NavigationAgent2D_property_debug_path_custom_point_size:
  239. .. rst-class:: classref-property
  240. :ref:`float<class_float>` **debug_path_custom_point_size** = ``4.0``
  241. .. rst-class:: classref-property-setget
  242. - void **set_debug_path_custom_point_size** **(** :ref:`float<class_float>` value **)**
  243. - :ref:`float<class_float>` **get_debug_path_custom_point_size** **(** **)**
  244. If :ref:`debug_use_custom<class_NavigationAgent2D_property_debug_use_custom>` is ``true`` uses this rasterized point size for rendering path points for this agent instead of global point size.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_NavigationAgent2D_property_debug_use_custom:
  248. .. rst-class:: classref-property
  249. :ref:`bool<class_bool>` **debug_use_custom** = ``false``
  250. .. rst-class:: classref-property-setget
  251. - void **set_debug_use_custom** **(** :ref:`bool<class_bool>` value **)**
  252. - :ref:`bool<class_bool>` **get_debug_use_custom** **(** **)**
  253. If ``true`` uses the defined :ref:`debug_path_custom_color<class_NavigationAgent2D_property_debug_path_custom_color>` for this agent instead of global color.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_NavigationAgent2D_property_max_neighbors:
  257. .. rst-class:: classref-property
  258. :ref:`int<class_int>` **max_neighbors** = ``10``
  259. .. rst-class:: classref-property-setget
  260. - void **set_max_neighbors** **(** :ref:`int<class_int>` value **)**
  261. - :ref:`int<class_int>` **get_max_neighbors** **(** **)**
  262. The maximum number of neighbors for the agent to consider.
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_NavigationAgent2D_property_max_speed:
  266. .. rst-class:: classref-property
  267. :ref:`float<class_float>` **max_speed** = ``100.0``
  268. .. rst-class:: classref-property-setget
  269. - void **set_max_speed** **(** :ref:`float<class_float>` value **)**
  270. - :ref:`float<class_float>` **get_max_speed** **(** **)**
  271. The maximum speed that an agent can move.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_NavigationAgent2D_property_navigation_layers:
  275. .. rst-class:: classref-property
  276. :ref:`int<class_int>` **navigation_layers** = ``1``
  277. .. rst-class:: classref-property-setget
  278. - void **set_navigation_layers** **(** :ref:`int<class_int>` value **)**
  279. - :ref:`int<class_int>` **get_navigation_layers** **(** **)**
  280. A bitfield determining which navigation layers of navigation regions this agent will use to calculate a path. Changing it during runtime will clear the current navigation path and generate a new one, according to the new navigation layers.
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_NavigationAgent2D_property_neighbor_distance:
  284. .. rst-class:: classref-property
  285. :ref:`float<class_float>` **neighbor_distance** = ``500.0``
  286. .. rst-class:: classref-property-setget
  287. - void **set_neighbor_distance** **(** :ref:`float<class_float>` value **)**
  288. - :ref:`float<class_float>` **get_neighbor_distance** **(** **)**
  289. The distance to search for other agents.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_NavigationAgent2D_property_path_desired_distance:
  293. .. rst-class:: classref-property
  294. :ref:`float<class_float>` **path_desired_distance** = ``20.0``
  295. .. rst-class:: classref-property-setget
  296. - void **set_path_desired_distance** **(** :ref:`float<class_float>` value **)**
  297. - :ref:`float<class_float>` **get_path_desired_distance** **(** **)**
  298. The distance threshold before a path point is considered to be reached. This allows agents to not have to hit a path point on the path exactly, but only to reach its general area. If this value is set too high, the NavigationAgent will skip points on the path, which can lead too leaving the navigation mesh. If this value is set too low, the NavigationAgent will be stuck in a repath loop because it will constantly overshoot or undershoot the distance to the next point on each physics frame update.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_NavigationAgent2D_property_path_max_distance:
  302. .. rst-class:: classref-property
  303. :ref:`float<class_float>` **path_max_distance** = ``100.0``
  304. .. rst-class:: classref-property-setget
  305. - void **set_path_max_distance** **(** :ref:`float<class_float>` value **)**
  306. - :ref:`float<class_float>` **get_path_max_distance** **(** **)**
  307. The maximum distance the agent is allowed away from the ideal path to the final position. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path.
  308. .. rst-class:: classref-item-separator
  309. ----
  310. .. _class_NavigationAgent2D_property_path_metadata_flags:
  311. .. rst-class:: classref-property
  312. :ref:`PathMetadataFlags<enum_NavigationPathQueryParameters2D_PathMetadataFlags>` **path_metadata_flags** = ``7``
  313. .. rst-class:: classref-property-setget
  314. - void **set_path_metadata_flags** **(** :ref:`PathMetadataFlags<enum_NavigationPathQueryParameters2D_PathMetadataFlags>` value **)**
  315. - :ref:`PathMetadataFlags<enum_NavigationPathQueryParameters2D_PathMetadataFlags>` **get_path_metadata_flags** **(** **)**
  316. Additional information to return with the navigation path.
  317. .. rst-class:: classref-item-separator
  318. ----
  319. .. _class_NavigationAgent2D_property_path_postprocessing:
  320. .. rst-class:: classref-property
  321. :ref:`PathPostProcessing<enum_NavigationPathQueryParameters2D_PathPostProcessing>` **path_postprocessing** = ``0``
  322. .. rst-class:: classref-property-setget
  323. - void **set_path_postprocessing** **(** :ref:`PathPostProcessing<enum_NavigationPathQueryParameters2D_PathPostProcessing>` value **)**
  324. - :ref:`PathPostProcessing<enum_NavigationPathQueryParameters2D_PathPostProcessing>` **get_path_postprocessing** **(** **)**
  325. The path postprocessing applied to the raw path corridor found by the :ref:`pathfinding_algorithm<class_NavigationAgent2D_property_pathfinding_algorithm>`.
  326. .. rst-class:: classref-item-separator
  327. ----
  328. .. _class_NavigationAgent2D_property_pathfinding_algorithm:
  329. .. rst-class:: classref-property
  330. :ref:`PathfindingAlgorithm<enum_NavigationPathQueryParameters2D_PathfindingAlgorithm>` **pathfinding_algorithm** = ``0``
  331. .. rst-class:: classref-property-setget
  332. - void **set_pathfinding_algorithm** **(** :ref:`PathfindingAlgorithm<enum_NavigationPathQueryParameters2D_PathfindingAlgorithm>` value **)**
  333. - :ref:`PathfindingAlgorithm<enum_NavigationPathQueryParameters2D_PathfindingAlgorithm>` **get_pathfinding_algorithm** **(** **)**
  334. The pathfinding algorithm used in the path query.
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_NavigationAgent2D_property_radius:
  338. .. rst-class:: classref-property
  339. :ref:`float<class_float>` **radius** = ``10.0``
  340. .. rst-class:: classref-property-setget
  341. - void **set_radius** **(** :ref:`float<class_float>` value **)**
  342. - :ref:`float<class_float>` **get_radius** **(** **)**
  343. The radius of the avoidance agent. This is the "body" of the avoidance agent and not the avoidance maneuver starting radius (which is controlled by :ref:`neighbor_distance<class_NavigationAgent2D_property_neighbor_distance>`).
  344. Does not affect normal pathfinding. To change an actor's pathfinding radius bake :ref:`NavigationMesh<class_NavigationMesh>` resources with a different :ref:`NavigationMesh.agent_radius<class_NavigationMesh_property_agent_radius>` property and use different navigation maps for each actor size.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_NavigationAgent2D_property_target_desired_distance:
  348. .. rst-class:: classref-property
  349. :ref:`float<class_float>` **target_desired_distance** = ``10.0``
  350. .. rst-class:: classref-property-setget
  351. - void **set_target_desired_distance** **(** :ref:`float<class_float>` value **)**
  352. - :ref:`float<class_float>` **get_target_desired_distance** **(** **)**
  353. The distance threshold before the final target point is considered to be reached. This allows agents to not have to hit the point of the final target exactly, but only to reach its general area. If this value is set too low, the NavigationAgent will be stuck in a repath loop because it will constantly overshoot or undershoot the distance to the final target point on each physics frame update.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_NavigationAgent2D_property_target_position:
  357. .. rst-class:: classref-property
  358. :ref:`Vector2<class_Vector2>` **target_position** = ``Vector2(0, 0)``
  359. .. rst-class:: classref-property-setget
  360. - void **set_target_position** **(** :ref:`Vector2<class_Vector2>` value **)**
  361. - :ref:`Vector2<class_Vector2>` **get_target_position** **(** **)**
  362. If set a new navigation path from the current agent position to the :ref:`target_position<class_NavigationAgent2D_property_target_position>` is requested from the NavigationServer.
  363. .. rst-class:: classref-item-separator
  364. ----
  365. .. _class_NavigationAgent2D_property_time_horizon_agents:
  366. .. rst-class:: classref-property
  367. :ref:`float<class_float>` **time_horizon_agents** = ``1.0``
  368. .. rst-class:: classref-property-setget
  369. - void **set_time_horizon_agents** **(** :ref:`float<class_float>` value **)**
  370. - :ref:`float<class_float>` **get_time_horizon_agents** **(** **)**
  371. 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. A too high value will slow down agents movement considerably. Must be positive.
  372. .. rst-class:: classref-item-separator
  373. ----
  374. .. _class_NavigationAgent2D_property_time_horizon_obstacles:
  375. .. rst-class:: classref-property
  376. :ref:`float<class_float>` **time_horizon_obstacles** = ``0.0``
  377. .. rst-class:: classref-property-setget
  378. - void **set_time_horizon_obstacles** **(** :ref:`float<class_float>` value **)**
  379. - :ref:`float<class_float>` **get_time_horizon_obstacles** **(** **)**
  380. The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithm, are safe with respect to static avoidance obstacles. The larger the number, the sooner the agent will respond to static avoidance obstacles, but less freedom in choosing its velocities. A too high value will slow down agents movement considerably. Must be positive.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_NavigationAgent2D_property_velocity:
  384. .. rst-class:: classref-property
  385. :ref:`Vector2<class_Vector2>` **velocity** = ``Vector2(0, 0)``
  386. .. rst-class:: classref-property-setget
  387. - void **set_velocity** **(** :ref:`Vector2<class_Vector2>` value **)**
  388. - :ref:`Vector2<class_Vector2>` **get_velocity** **(** **)**
  389. Sets the new wanted velocity for the agent. The avoidance simulation will try to fulfill this velocity if possible but will modify it to avoid collision with other agents and obstacles. When an agent is teleported to a new position, use :ref:`set_velocity_forced<class_NavigationAgent2D_method_set_velocity_forced>` as well to reset the internal simulation velocity.
  390. .. rst-class:: classref-section-separator
  391. ----
  392. .. rst-class:: classref-descriptions-group
  393. Method Descriptions
  394. -------------------
  395. .. _class_NavigationAgent2D_method_distance_to_target:
  396. .. rst-class:: classref-method
  397. :ref:`float<class_float>` **distance_to_target** **(** **)** |const|
  398. Returns the distance to the target position, using the agent's global position. The user must set :ref:`target_position<class_NavigationAgent2D_property_target_position>` in order for this to be accurate.
  399. .. rst-class:: classref-item-separator
  400. ----
  401. .. _class_NavigationAgent2D_method_get_avoidance_layer_value:
  402. .. rst-class:: classref-method
  403. :ref:`bool<class_bool>` **get_avoidance_layer_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  404. Returns whether or not the specified layer of the :ref:`avoidance_layers<class_NavigationAgent2D_property_avoidance_layers>` bitmask is enabled, given a ``layer_number`` between 1 and 32.
  405. .. rst-class:: classref-item-separator
  406. ----
  407. .. _class_NavigationAgent2D_method_get_avoidance_mask_value:
  408. .. rst-class:: classref-method
  409. :ref:`bool<class_bool>` **get_avoidance_mask_value** **(** :ref:`int<class_int>` mask_number **)** |const|
  410. Returns whether or not the specified mask of the :ref:`avoidance_mask<class_NavigationAgent2D_property_avoidance_mask>` bitmask is enabled, given a ``mask_number`` between 1 and 32.
  411. .. rst-class:: classref-item-separator
  412. ----
  413. .. _class_NavigationAgent2D_method_get_current_navigation_path:
  414. .. rst-class:: classref-method
  415. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_current_navigation_path** **(** **)** |const|
  416. Returns this agent's current path from start to finish in global coordinates. The path only updates when the target position is changed or the agent requires a repath. The path array is not intended to be used in direct path movement as the agent has its own internal path logic that would get corrupted by changing the path array manually. Use the intended :ref:`get_next_path_position<class_NavigationAgent2D_method_get_next_path_position>` once every physics frame to receive the next path point for the agents movement as this function also updates the internal path logic.
  417. .. rst-class:: classref-item-separator
  418. ----
  419. .. _class_NavigationAgent2D_method_get_current_navigation_path_index:
  420. .. rst-class:: classref-method
  421. :ref:`int<class_int>` **get_current_navigation_path_index** **(** **)** |const|
  422. Returns which index the agent is currently on in the navigation path's :ref:`PackedVector2Array<class_PackedVector2Array>`.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_NavigationAgent2D_method_get_current_navigation_result:
  426. .. rst-class:: classref-method
  427. :ref:`NavigationPathQueryResult2D<class_NavigationPathQueryResult2D>` **get_current_navigation_result** **(** **)** |const|
  428. Returns the path query result for the path the agent is currently following.
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _class_NavigationAgent2D_method_get_final_position:
  432. .. rst-class:: classref-method
  433. :ref:`Vector2<class_Vector2>` **get_final_position** **(** **)**
  434. Returns the reachable final position of the current navigation path 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.
  435. .. rst-class:: classref-item-separator
  436. ----
  437. .. _class_NavigationAgent2D_method_get_navigation_layer_value:
  438. .. rst-class:: classref-method
  439. :ref:`bool<class_bool>` **get_navigation_layer_value** **(** :ref:`int<class_int>` layer_number **)** |const|
  440. Returns whether or not the specified layer of the :ref:`navigation_layers<class_NavigationAgent2D_property_navigation_layers>` bitmask is enabled, given a ``layer_number`` between 1 and 32.
  441. .. rst-class:: classref-item-separator
  442. ----
  443. .. _class_NavigationAgent2D_method_get_navigation_map:
  444. .. rst-class:: classref-method
  445. :ref:`RID<class_RID>` **get_navigation_map** **(** **)** |const|
  446. Returns the :ref:`RID<class_RID>` of the navigation map for this NavigationAgent node. This function returns always the map set on the NavigationAgent node and not the map of the abstract agent on the NavigationServer. If the agent map is changed directly with the NavigationServer API the NavigationAgent node will not be aware of the map change. Use :ref:`set_navigation_map<class_NavigationAgent2D_method_set_navigation_map>` to change the navigation map for the NavigationAgent and also update the agent on the NavigationServer.
  447. .. rst-class:: classref-item-separator
  448. ----
  449. .. _class_NavigationAgent2D_method_get_next_path_position:
  450. .. rst-class:: classref-method
  451. :ref:`Vector2<class_Vector2>` **get_next_path_position** **(** **)**
  452. Returns the next position 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. The use of this function once every physics frame is required to update the internal path logic of the NavigationAgent.
  453. .. rst-class:: classref-item-separator
  454. ----
  455. .. _class_NavigationAgent2D_method_get_rid:
  456. .. rst-class:: classref-method
  457. :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  458. Returns the :ref:`RID<class_RID>` of this agent on the :ref:`NavigationServer2D<class_NavigationServer2D>`.
  459. .. rst-class:: classref-item-separator
  460. ----
  461. .. _class_NavigationAgent2D_method_is_navigation_finished:
  462. .. rst-class:: classref-method
  463. :ref:`bool<class_bool>` **is_navigation_finished** **(** **)**
  464. Returns true if the navigation path's final position has been reached.
  465. .. rst-class:: classref-item-separator
  466. ----
  467. .. _class_NavigationAgent2D_method_is_target_reachable:
  468. .. rst-class:: classref-method
  469. :ref:`bool<class_bool>` **is_target_reachable** **(** **)**
  470. Returns true if :ref:`target_position<class_NavigationAgent2D_property_target_position>` is reachable. The target position is set using :ref:`target_position<class_NavigationAgent2D_property_target_position>`.
  471. .. rst-class:: classref-item-separator
  472. ----
  473. .. _class_NavigationAgent2D_method_is_target_reached:
  474. .. rst-class:: classref-method
  475. :ref:`bool<class_bool>` **is_target_reached** **(** **)** |const|
  476. Returns true if :ref:`target_position<class_NavigationAgent2D_property_target_position>` is reached. It may not always be possible to reach the target position. It should always be possible to reach the final position though. See :ref:`get_final_position<class_NavigationAgent2D_method_get_final_position>`.
  477. .. rst-class:: classref-item-separator
  478. ----
  479. .. _class_NavigationAgent2D_method_set_avoidance_layer_value:
  480. .. rst-class:: classref-method
  481. void **set_avoidance_layer_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  482. Based on ``value``, enables or disables the specified layer in the :ref:`avoidance_layers<class_NavigationAgent2D_property_avoidance_layers>` bitmask, given a ``layer_number`` between 1 and 32.
  483. .. rst-class:: classref-item-separator
  484. ----
  485. .. _class_NavigationAgent2D_method_set_avoidance_mask_value:
  486. .. rst-class:: classref-method
  487. void **set_avoidance_mask_value** **(** :ref:`int<class_int>` mask_number, :ref:`bool<class_bool>` value **)**
  488. Based on ``value``, enables or disables the specified mask in the :ref:`avoidance_mask<class_NavigationAgent2D_property_avoidance_mask>` bitmask, given a ``mask_number`` between 1 and 32.
  489. .. rst-class:: classref-item-separator
  490. ----
  491. .. _class_NavigationAgent2D_method_set_navigation_layer_value:
  492. .. rst-class:: classref-method
  493. void **set_navigation_layer_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
  494. Based on ``value``, enables or disables the specified layer in the :ref:`navigation_layers<class_NavigationAgent2D_property_navigation_layers>` bitmask, given a ``layer_number`` between 1 and 32.
  495. .. rst-class:: classref-item-separator
  496. ----
  497. .. _class_NavigationAgent2D_method_set_navigation_map:
  498. .. rst-class:: classref-method
  499. void **set_navigation_map** **(** :ref:`RID<class_RID>` navigation_map **)**
  500. Sets the :ref:`RID<class_RID>` of the navigation map this NavigationAgent node should use and also updates the ``agent`` on the NavigationServer.
  501. .. rst-class:: classref-item-separator
  502. ----
  503. .. _class_NavigationAgent2D_method_set_velocity_forced:
  504. .. rst-class:: classref-method
  505. void **set_velocity_forced** **(** :ref:`Vector2<class_Vector2>` velocity **)**
  506. Replaces the internal velocity in the collision avoidance simulation with ``velocity``. When an agent is teleported to a new position this function should be used in the same frame. If called frequently this function can get agents stuck.
  507. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  508. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  509. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  510. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  511. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  512. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`