class_astargrid2d.rst 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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/4.3/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.3/doc/classes/AStarGrid2D.xml.
  6. .. _class_AStarGrid2D:
  7. AStarGrid2D
  8. ===========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. An implementation of A\* for finding the shortest path between two points on a partial 2D grid.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **AStarGrid2D** is a variant of :ref:`AStar2D<class_AStar2D>` that is specialized for partial 2D grids. It is simpler to use because it doesn't require you to manually create points and connect them together. This class also supports multiple types of heuristics, modes for diagonal movement, and a jumping mode to speed up calculations.
  15. To use **AStarGrid2D**, you only need to set the :ref:`region<class_AStarGrid2D_property_region>` of the grid, optionally set the :ref:`cell_size<class_AStarGrid2D_property_cell_size>`, and then call the :ref:`update<class_AStarGrid2D_method_update>` method:
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. var astar_grid = AStarGrid2D.new()
  19. astar_grid.region = Rect2i(0, 0, 32, 32)
  20. astar_grid.cell_size = Vector2(16, 16)
  21. astar_grid.update()
  22. print(astar_grid.get_id_path(Vector2i(0, 0), Vector2i(3, 4))) # prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
  23. print(astar_grid.get_point_path(Vector2i(0, 0), Vector2i(3, 4))) # prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
  24. .. code-tab:: csharp
  25. AStarGrid2D astarGrid = new AStarGrid2D();
  26. astarGrid.Region = new Rect2I(0, 0, 32, 32);
  27. astarGrid.CellSize = new Vector2I(16, 16);
  28. astarGrid.Update();
  29. GD.Print(astarGrid.GetIdPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
  30. GD.Print(astarGrid.GetPointPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
  31. To remove a point from the pathfinding grid, it must be set as "solid" with :ref:`set_point_solid<class_AStarGrid2D_method_set_point_solid>`.
  32. .. rst-class:: classref-reftable-group
  33. Properties
  34. ----------
  35. .. table::
  36. :widths: auto
  37. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  38. | :ref:`CellShape<enum_AStarGrid2D_CellShape>` | :ref:`cell_shape<class_AStarGrid2D_property_cell_shape>` | ``0`` |
  39. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  40. | :ref:`Vector2<class_Vector2>` | :ref:`cell_size<class_AStarGrid2D_property_cell_size>` | ``Vector2(1, 1)`` |
  41. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  42. | :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_compute_heuristic<class_AStarGrid2D_property_default_compute_heuristic>` | ``0`` |
  43. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  44. | :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_estimate_heuristic<class_AStarGrid2D_property_default_estimate_heuristic>` | ``0`` |
  45. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  46. | :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` | :ref:`diagonal_mode<class_AStarGrid2D_property_diagonal_mode>` | ``0`` |
  47. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`jumping_enabled<class_AStarGrid2D_property_jumping_enabled>` | ``false`` |
  49. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  50. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AStarGrid2D_property_offset>` | ``Vector2(0, 0)`` |
  51. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  52. | :ref:`Rect2i<class_Rect2i>` | :ref:`region<class_AStarGrid2D_property_region>` | ``Rect2i(0, 0, 0, 0)`` |
  53. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  54. | :ref:`Vector2i<class_Vector2i>` | :ref:`size<class_AStarGrid2D_property_size>` | ``Vector2i(0, 0)`` |
  55. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  56. .. rst-class:: classref-reftable-group
  57. Methods
  58. -------
  59. .. table::
  60. :widths: auto
  61. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`_compute_cost<class_AStarGrid2D_private_method__compute_cost>`\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| |
  63. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`_estimate_cost<class_AStarGrid2D_private_method__estimate_cost>`\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| |
  65. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | |void| | :ref:`clear<class_AStarGrid2D_method_clear>`\ (\ ) |
  67. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | |void| | :ref:`fill_solid_region<class_AStarGrid2D_method_fill_solid_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`, solid\: :ref:`bool<class_bool>` = true\ ) |
  69. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | |void| | :ref:`fill_weight_scale_region<class_AStarGrid2D_method_fill_weight_scale_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`, weight_scale\: :ref:`float<class_float>`\ ) |
  71. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] | :ref:`get_id_path<class_AStarGrid2D_method_get_id_path>`\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
  73. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_point_path<class_AStarGrid2D_method_get_point_path>`\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
  75. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_AStarGrid2D_method_get_point_position>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
  77. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`float<class_float>` | :ref:`get_point_weight_scale<class_AStarGrid2D_method_get_point_weight_scale>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
  79. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_dirty<class_AStarGrid2D_method_is_dirty>`\ (\ ) |const| |
  81. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`bool<class_bool>` | :ref:`is_in_bounds<class_AStarGrid2D_method_is_in_bounds>`\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`\ ) |const| |
  83. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`is_in_boundsv<class_AStarGrid2D_method_is_in_boundsv>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
  85. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`bool<class_bool>` | :ref:`is_point_solid<class_AStarGrid2D_method_is_point_solid>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
  87. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | |void| | :ref:`set_point_solid<class_AStarGrid2D_method_set_point_solid>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`, solid\: :ref:`bool<class_bool>` = true\ ) |
  89. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | |void| | :ref:`set_point_weight_scale<class_AStarGrid2D_method_set_point_weight_scale>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`, weight_scale\: :ref:`float<class_float>`\ ) |
  91. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | |void| | :ref:`update<class_AStarGrid2D_method_update>`\ (\ ) |
  93. +--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. .. rst-class:: classref-section-separator
  95. ----
  96. .. rst-class:: classref-descriptions-group
  97. Enumerations
  98. ------------
  99. .. _enum_AStarGrid2D_Heuristic:
  100. .. rst-class:: classref-enumeration
  101. enum **Heuristic**: :ref:`🔗<enum_AStarGrid2D_Heuristic>`
  102. .. _class_AStarGrid2D_constant_HEURISTIC_EUCLIDEAN:
  103. .. rst-class:: classref-enumeration-constant
  104. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_EUCLIDEAN** = ``0``
  105. The `Euclidean heuristic <https://en.wikipedia.org/wiki/Euclidean_distance>`__ to be used for the pathfinding using the following formula:
  106. ::
  107. dx = abs(to_id.x - from_id.x)
  108. dy = abs(to_id.y - from_id.y)
  109. result = sqrt(dx * dx + dy * dy)
  110. \ **Note:** This is also the internal heuristic used in :ref:`AStar3D<class_AStar3D>` and :ref:`AStar2D<class_AStar2D>` by default (with the inclusion of possible z-axis coordinate).
  111. .. _class_AStarGrid2D_constant_HEURISTIC_MANHATTAN:
  112. .. rst-class:: classref-enumeration-constant
  113. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MANHATTAN** = ``1``
  114. The `Manhattan heuristic <https://en.wikipedia.org/wiki/Taxicab_geometry>`__ to be used for the pathfinding using the following formula:
  115. ::
  116. dx = abs(to_id.x - from_id.x)
  117. dy = abs(to_id.y - from_id.y)
  118. result = dx + dy
  119. \ **Note:** This heuristic is intended to be used with 4-side orthogonal movements, provided by setting the :ref:`diagonal_mode<class_AStarGrid2D_property_diagonal_mode>` to :ref:`DIAGONAL_MODE_NEVER<class_AStarGrid2D_constant_DIAGONAL_MODE_NEVER>`.
  120. .. _class_AStarGrid2D_constant_HEURISTIC_OCTILE:
  121. .. rst-class:: classref-enumeration-constant
  122. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_OCTILE** = ``2``
  123. The Octile heuristic to be used for the pathfinding using the following formula:
  124. ::
  125. dx = abs(to_id.x - from_id.x)
  126. dy = abs(to_id.y - from_id.y)
  127. f = sqrt(2) - 1
  128. result = (dx < dy) ? f * dx + dy : f * dy + dx;
  129. .. _class_AStarGrid2D_constant_HEURISTIC_CHEBYSHEV:
  130. .. rst-class:: classref-enumeration-constant
  131. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_CHEBYSHEV** = ``3``
  132. The `Chebyshev heuristic <https://en.wikipedia.org/wiki/Chebyshev_distance>`__ to be used for the pathfinding using the following formula:
  133. ::
  134. dx = abs(to_id.x - from_id.x)
  135. dy = abs(to_id.y - from_id.y)
  136. result = max(dx, dy)
  137. .. _class_AStarGrid2D_constant_HEURISTIC_MAX:
  138. .. rst-class:: classref-enumeration-constant
  139. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MAX** = ``4``
  140. Represents the size of the :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` enum.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _enum_AStarGrid2D_DiagonalMode:
  144. .. rst-class:: classref-enumeration
  145. enum **DiagonalMode**: :ref:`🔗<enum_AStarGrid2D_DiagonalMode>`
  146. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_ALWAYS:
  147. .. rst-class:: classref-enumeration-constant
  148. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ALWAYS** = ``0``
  149. The pathfinding algorithm will ignore solid neighbors around the target cell and allow passing using diagonals.
  150. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_NEVER:
  151. .. rst-class:: classref-enumeration-constant
  152. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_NEVER** = ``1``
  153. The pathfinding algorithm will ignore all diagonals and the way will be always orthogonal.
  154. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE:
  155. .. rst-class:: classref-enumeration-constant
  156. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE** = ``2``
  157. The pathfinding algorithm will avoid using diagonals if at least two obstacles have been placed around the neighboring cells of the specific path segment.
  158. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES:
  159. .. rst-class:: classref-enumeration-constant
  160. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES** = ``3``
  161. The pathfinding algorithm will avoid using diagonals if any obstacle has been placed around the neighboring cells of the specific path segment.
  162. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_MAX:
  163. .. rst-class:: classref-enumeration-constant
  164. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_MAX** = ``4``
  165. Represents the size of the :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` enum.
  166. .. rst-class:: classref-item-separator
  167. ----
  168. .. _enum_AStarGrid2D_CellShape:
  169. .. rst-class:: classref-enumeration
  170. enum **CellShape**: :ref:`🔗<enum_AStarGrid2D_CellShape>`
  171. .. _class_AStarGrid2D_constant_CELL_SHAPE_SQUARE:
  172. .. rst-class:: classref-enumeration-constant
  173. :ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_SQUARE** = ``0``
  174. Rectangular cell shape.
  175. .. _class_AStarGrid2D_constant_CELL_SHAPE_ISOMETRIC_RIGHT:
  176. .. rst-class:: classref-enumeration-constant
  177. :ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_ISOMETRIC_RIGHT** = ``1``
  178. Diamond cell shape (for isometric look). Cell coordinates layout where the horizontal axis goes up-right, and the vertical one goes down-right.
  179. .. _class_AStarGrid2D_constant_CELL_SHAPE_ISOMETRIC_DOWN:
  180. .. rst-class:: classref-enumeration-constant
  181. :ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_ISOMETRIC_DOWN** = ``2``
  182. Diamond cell shape (for isometric look). Cell coordinates layout where the horizontal axis goes down-right, and the vertical one goes down-left.
  183. .. _class_AStarGrid2D_constant_CELL_SHAPE_MAX:
  184. .. rst-class:: classref-enumeration-constant
  185. :ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_MAX** = ``3``
  186. Represents the size of the :ref:`CellShape<enum_AStarGrid2D_CellShape>` enum.
  187. .. rst-class:: classref-section-separator
  188. ----
  189. .. rst-class:: classref-descriptions-group
  190. Property Descriptions
  191. ---------------------
  192. .. _class_AStarGrid2D_property_cell_shape:
  193. .. rst-class:: classref-property
  194. :ref:`CellShape<enum_AStarGrid2D_CellShape>` **cell_shape** = ``0`` :ref:`🔗<class_AStarGrid2D_property_cell_shape>`
  195. .. rst-class:: classref-property-setget
  196. - |void| **set_cell_shape**\ (\ value\: :ref:`CellShape<enum_AStarGrid2D_CellShape>`\ )
  197. - :ref:`CellShape<enum_AStarGrid2D_CellShape>` **get_cell_shape**\ (\ )
  198. The cell shape. Affects how the positions are placed in the grid. If changed, :ref:`update<class_AStarGrid2D_method_update>` needs to be called before finding the next path.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_AStarGrid2D_property_cell_size:
  202. .. rst-class:: classref-property
  203. :ref:`Vector2<class_Vector2>` **cell_size** = ``Vector2(1, 1)`` :ref:`🔗<class_AStarGrid2D_property_cell_size>`
  204. .. rst-class:: classref-property-setget
  205. - |void| **set_cell_size**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  206. - :ref:`Vector2<class_Vector2>` **get_cell_size**\ (\ )
  207. The size of the point cell which will be applied to calculate the resulting point position returned by :ref:`get_point_path<class_AStarGrid2D_method_get_point_path>`. If changed, :ref:`update<class_AStarGrid2D_method_update>` needs to be called before finding the next path.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_AStarGrid2D_property_default_compute_heuristic:
  211. .. rst-class:: classref-property
  212. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_compute_heuristic** = ``0`` :ref:`🔗<class_AStarGrid2D_property_default_compute_heuristic>`
  213. .. rst-class:: classref-property-setget
  214. - |void| **set_default_compute_heuristic**\ (\ value\: :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`\ )
  215. - :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_compute_heuristic**\ (\ )
  216. The default :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` which will be used to calculate the cost between two points if :ref:`_compute_cost<class_AStarGrid2D_private_method__compute_cost>` was not overridden.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_AStarGrid2D_property_default_estimate_heuristic:
  220. .. rst-class:: classref-property
  221. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_estimate_heuristic** = ``0`` :ref:`🔗<class_AStarGrid2D_property_default_estimate_heuristic>`
  222. .. rst-class:: classref-property-setget
  223. - |void| **set_default_estimate_heuristic**\ (\ value\: :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`\ )
  224. - :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_estimate_heuristic**\ (\ )
  225. The default :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` which will be used to calculate the cost between the point and the end point if :ref:`_estimate_cost<class_AStarGrid2D_private_method__estimate_cost>` was not overridden.
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_AStarGrid2D_property_diagonal_mode:
  229. .. rst-class:: classref-property
  230. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **diagonal_mode** = ``0`` :ref:`🔗<class_AStarGrid2D_property_diagonal_mode>`
  231. .. rst-class:: classref-property-setget
  232. - |void| **set_diagonal_mode**\ (\ value\: :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>`\ )
  233. - :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **get_diagonal_mode**\ (\ )
  234. A specific :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` mode which will force the path to avoid or accept the specified diagonals.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_AStarGrid2D_property_jumping_enabled:
  238. .. rst-class:: classref-property
  239. :ref:`bool<class_bool>` **jumping_enabled** = ``false`` :ref:`🔗<class_AStarGrid2D_property_jumping_enabled>`
  240. .. rst-class:: classref-property-setget
  241. - |void| **set_jumping_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  242. - :ref:`bool<class_bool>` **is_jumping_enabled**\ (\ )
  243. Enables or disables jumping to skip up the intermediate points and speeds up the searching algorithm.
  244. \ **Note:** Currently, toggling it on disables the consideration of weight scaling in pathfinding.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_AStarGrid2D_property_offset:
  248. .. rst-class:: classref-property
  249. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_AStarGrid2D_property_offset>`
  250. .. rst-class:: classref-property-setget
  251. - |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  252. - :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
  253. The offset of the grid which will be applied to calculate the resulting point position returned by :ref:`get_point_path<class_AStarGrid2D_method_get_point_path>`. If changed, :ref:`update<class_AStarGrid2D_method_update>` needs to be called before finding the next path.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_AStarGrid2D_property_region:
  257. .. rst-class:: classref-property
  258. :ref:`Rect2i<class_Rect2i>` **region** = ``Rect2i(0, 0, 0, 0)`` :ref:`🔗<class_AStarGrid2D_property_region>`
  259. .. rst-class:: classref-property-setget
  260. - |void| **set_region**\ (\ value\: :ref:`Rect2i<class_Rect2i>`\ )
  261. - :ref:`Rect2i<class_Rect2i>` **get_region**\ (\ )
  262. The region of grid cells available for pathfinding. If changed, :ref:`update<class_AStarGrid2D_method_update>` needs to be called before finding the next path.
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_AStarGrid2D_property_size:
  266. .. rst-class:: classref-property
  267. :ref:`Vector2i<class_Vector2i>` **size** = ``Vector2i(0, 0)`` :ref:`🔗<class_AStarGrid2D_property_size>`
  268. .. rst-class:: classref-property-setget
  269. - |void| **set_size**\ (\ value\: :ref:`Vector2i<class_Vector2i>`\ )
  270. - :ref:`Vector2i<class_Vector2i>` **get_size**\ (\ )
  271. **Deprecated:** Use :ref:`region<class_AStarGrid2D_property_region>` instead.
  272. The size of the grid (number of cells of size :ref:`cell_size<class_AStarGrid2D_property_cell_size>` on each axis). If changed, :ref:`update<class_AStarGrid2D_method_update>` needs to be called before finding the next path.
  273. .. rst-class:: classref-section-separator
  274. ----
  275. .. rst-class:: classref-descriptions-group
  276. Method Descriptions
  277. -------------------
  278. .. _class_AStarGrid2D_private_method__compute_cost:
  279. .. rst-class:: classref-method
  280. :ref:`float<class_float>` **_compute_cost**\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| :ref:`🔗<class_AStarGrid2D_private_method__compute_cost>`
  281. Called when computing the cost between two connected points.
  282. Note that this function is hidden in the default **AStarGrid2D** class.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_AStarGrid2D_private_method__estimate_cost:
  286. .. rst-class:: classref-method
  287. :ref:`float<class_float>` **_estimate_cost**\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| :ref:`🔗<class_AStarGrid2D_private_method__estimate_cost>`
  288. Called when estimating the cost between a point and the path's ending point.
  289. Note that this function is hidden in the default **AStarGrid2D** class.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_AStarGrid2D_method_clear:
  293. .. rst-class:: classref-method
  294. |void| **clear**\ (\ ) :ref:`🔗<class_AStarGrid2D_method_clear>`
  295. Clears the grid and sets the :ref:`region<class_AStarGrid2D_property_region>` to ``Rect2i(0, 0, 0, 0)``.
  296. .. rst-class:: classref-item-separator
  297. ----
  298. .. _class_AStarGrid2D_method_fill_solid_region:
  299. .. rst-class:: classref-method
  300. |void| **fill_solid_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`, solid\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStarGrid2D_method_fill_solid_region>`
  301. Fills the given ``region`` on the grid with the specified value for the solid flag.
  302. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_AStarGrid2D_method_fill_weight_scale_region:
  306. .. rst-class:: classref-method
  307. |void| **fill_weight_scale_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStarGrid2D_method_fill_weight_scale_region>`
  308. Fills the given ``region`` on the grid with the specified value for the weight scale.
  309. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  310. .. rst-class:: classref-item-separator
  311. ----
  312. .. _class_AStarGrid2D_method_get_id_path:
  313. .. rst-class:: classref-method
  314. :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] **get_id_path**\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStarGrid2D_method_get_id_path>`
  315. Returns an array with the IDs of the points that form the path found by AStar2D between the given points. The array is ordered from the starting point to the ending point of the path.
  316. If there is no valid path to the target, and ``allow_partial_path`` is ``true``, returns a path to the point closest to the target that can be reached.
  317. .. rst-class:: classref-item-separator
  318. ----
  319. .. _class_AStarGrid2D_method_get_point_path:
  320. .. rst-class:: classref-method
  321. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_point_path**\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, to_id\: :ref:`Vector2i<class_Vector2i>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStarGrid2D_method_get_point_path>`
  322. Returns an array with the points that are in the path found by **AStarGrid2D** between the given points. The array is ordered from the starting point to the ending point of the path.
  323. If there is no valid path to the target, and ``allow_partial_path`` is ``true``, returns a path to the point closest to the target that can be reached.
  324. \ **Note:** This method is not thread-safe. If called from a :ref:`Thread<class_Thread>`, it will return an empty array and will print an error message.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_AStarGrid2D_method_get_point_position:
  328. .. rst-class:: classref-method
  329. :ref:`Vector2<class_Vector2>` **get_point_position**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_get_point_position>`
  330. Returns the position of the point associated with the given ``id``.
  331. .. rst-class:: classref-item-separator
  332. ----
  333. .. _class_AStarGrid2D_method_get_point_weight_scale:
  334. .. rst-class:: classref-method
  335. :ref:`float<class_float>` **get_point_weight_scale**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_get_point_weight_scale>`
  336. Returns the weight scale of the point associated with the given ``id``.
  337. .. rst-class:: classref-item-separator
  338. ----
  339. .. _class_AStarGrid2D_method_is_dirty:
  340. .. rst-class:: classref-method
  341. :ref:`bool<class_bool>` **is_dirty**\ (\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_dirty>`
  342. Indicates that the grid parameters were changed and :ref:`update<class_AStarGrid2D_method_update>` needs to be called.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_AStarGrid2D_method_is_in_bounds:
  346. .. rst-class:: classref-method
  347. :ref:`bool<class_bool>` **is_in_bounds**\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_in_bounds>`
  348. Returns ``true`` if the ``x`` and ``y`` is a valid grid coordinate (id), i.e. if it is inside :ref:`region<class_AStarGrid2D_property_region>`. Equivalent to ``region.has_point(Vector2i(x, y))``.
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_AStarGrid2D_method_is_in_boundsv:
  352. .. rst-class:: classref-method
  353. :ref:`bool<class_bool>` **is_in_boundsv**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_in_boundsv>`
  354. Returns ``true`` if the ``id`` vector is a valid grid coordinate, i.e. if it is inside :ref:`region<class_AStarGrid2D_property_region>`. Equivalent to ``region.has_point(id)``.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_AStarGrid2D_method_is_point_solid:
  358. .. rst-class:: classref-method
  359. :ref:`bool<class_bool>` **is_point_solid**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_point_solid>`
  360. Returns ``true`` if a point is disabled for pathfinding. By default, all points are enabled.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_AStarGrid2D_method_set_point_solid:
  364. .. rst-class:: classref-method
  365. |void| **set_point_solid**\ (\ id\: :ref:`Vector2i<class_Vector2i>`, solid\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStarGrid2D_method_set_point_solid>`
  366. Disables or enables the specified point for pathfinding. Useful for making an obstacle. By default, all points are enabled.
  367. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_AStarGrid2D_method_set_point_weight_scale:
  371. .. rst-class:: classref-method
  372. |void| **set_point_weight_scale**\ (\ id\: :ref:`Vector2i<class_Vector2i>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStarGrid2D_method_set_point_weight_scale>`
  373. Sets the ``weight_scale`` for the point with the given ``id``. The ``weight_scale`` is multiplied by the result of :ref:`_compute_cost<class_AStarGrid2D_private_method__compute_cost>` when determining the overall cost of traveling across a segment from a neighboring point to this point.
  374. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_AStarGrid2D_method_update:
  378. .. rst-class:: classref-method
  379. |void| **update**\ (\ ) :ref:`🔗<class_AStarGrid2D_method_update>`
  380. Updates the internal state of the grid according to the parameters to prepare it to search the path. Needs to be called if parameters like :ref:`region<class_AStarGrid2D_property_region>`, :ref:`cell_size<class_AStarGrid2D_property_cell_size>` or :ref:`offset<class_AStarGrid2D_property_offset>` are changed. :ref:`is_dirty<class_AStarGrid2D_method_is_dirty>` will return ``true`` if this is the case and this needs to be called.
  381. \ **Note:** All point data (solidity and weight scale) will be cleared.
  382. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  383. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  384. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  385. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  386. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  387. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  388. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  389. .. |void| replace:: :abbr:`void (No return value.)`