class_astargrid2d.rst 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/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:`Vector2<class_Vector2>` | :ref:`cell_size<class_AStarGrid2D_property_cell_size>` | ``Vector2(1, 1)`` |
  39. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  40. | :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_compute_heuristic<class_AStarGrid2D_property_default_compute_heuristic>` | ``0`` |
  41. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  42. | :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_estimate_heuristic<class_AStarGrid2D_property_default_estimate_heuristic>` | ``0`` |
  43. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  44. | :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` | :ref:`diagonal_mode<class_AStarGrid2D_property_diagonal_mode>` | ``0`` |
  45. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`jumping_enabled<class_AStarGrid2D_property_jumping_enabled>` | ``false`` |
  47. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  48. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AStarGrid2D_property_offset>` | ``Vector2(0, 0)`` |
  49. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  50. | :ref:`Rect2i<class_Rect2i>` | :ref:`region<class_AStarGrid2D_property_region>` | ``Rect2i(0, 0, 0, 0)`` |
  51. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  52. | :ref:`Vector2i<class_Vector2i>` | :ref:`size<class_AStarGrid2D_property_size>` | ``Vector2i(0, 0)`` |
  53. +----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`float<class_float>` | :ref:`_compute_cost<class_AStarGrid2D_private_method__compute_cost>` **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |virtual| |const| |
  61. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`_estimate_cost<class_AStarGrid2D_private_method__estimate_cost>` **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |virtual| |const| |
  63. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`clear<class_AStarGrid2D_method_clear>` **(** **)** |
  65. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`fill_solid_region<class_AStarGrid2D_method_fill_solid_region>` **(** :ref:`Rect2i<class_Rect2i>` region, :ref:`bool<class_bool>` solid=true **)** |
  67. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`fill_weight_scale_region<class_AStarGrid2D_method_fill_weight_scale_region>` **(** :ref:`Rect2i<class_Rect2i>` region, :ref:`float<class_float>` weight_scale **)** |
  69. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Vector2i[]<class_Vector2i>` | :ref:`get_id_path<class_AStarGrid2D_method_get_id_path>` **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |
  71. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_point_path<class_AStarGrid2D_method_get_point_path>` **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |
  73. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_AStarGrid2D_method_get_point_position>` **(** :ref:`Vector2i<class_Vector2i>` id **)** |const| |
  75. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`float<class_float>` | :ref:`get_point_weight_scale<class_AStarGrid2D_method_get_point_weight_scale>` **(** :ref:`Vector2i<class_Vector2i>` id **)** |const| |
  77. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`is_dirty<class_AStarGrid2D_method_is_dirty>` **(** **)** |const| |
  79. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_in_bounds<class_AStarGrid2D_method_is_in_bounds>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  81. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`bool<class_bool>` | :ref:`is_in_boundsv<class_AStarGrid2D_method_is_in_boundsv>` **(** :ref:`Vector2i<class_Vector2i>` id **)** |const| |
  83. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`is_point_solid<class_AStarGrid2D_method_is_point_solid>` **(** :ref:`Vector2i<class_Vector2i>` id **)** |const| |
  85. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`set_point_solid<class_AStarGrid2D_method_set_point_solid>` **(** :ref:`Vector2i<class_Vector2i>` id, :ref:`bool<class_bool>` solid=true **)** |
  87. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`set_point_weight_scale<class_AStarGrid2D_method_set_point_weight_scale>` **(** :ref:`Vector2i<class_Vector2i>` id, :ref:`float<class_float>` weight_scale **)** |
  89. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`update<class_AStarGrid2D_method_update>` **(** **)** |
  91. +-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Enumerations
  96. ------------
  97. .. _enum_AStarGrid2D_Heuristic:
  98. .. rst-class:: classref-enumeration
  99. enum **Heuristic**:
  100. .. _class_AStarGrid2D_constant_HEURISTIC_EUCLIDEAN:
  101. .. rst-class:: classref-enumeration-constant
  102. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_EUCLIDEAN** = ``0``
  103. The `Euclidean heuristic <https://en.wikipedia.org/wiki/Euclidean_distance>`__ to be used for the pathfinding using the following formula:
  104. ::
  105. dx = abs(to_id.x - from_id.x)
  106. dy = abs(to_id.y - from_id.y)
  107. result = sqrt(dx * dx + dy * dy)
  108. \ **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).
  109. .. _class_AStarGrid2D_constant_HEURISTIC_MANHATTAN:
  110. .. rst-class:: classref-enumeration-constant
  111. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MANHATTAN** = ``1``
  112. The `Manhattan heuristic <https://en.wikipedia.org/wiki/Taxicab_geometry>`__ to be used for the pathfinding using the following formula:
  113. ::
  114. dx = abs(to_id.x - from_id.x)
  115. dy = abs(to_id.y - from_id.y)
  116. result = dx + dy
  117. \ **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>`.
  118. .. _class_AStarGrid2D_constant_HEURISTIC_OCTILE:
  119. .. rst-class:: classref-enumeration-constant
  120. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_OCTILE** = ``2``
  121. The Octile heuristic to be used for the pathfinding using the following formula:
  122. ::
  123. dx = abs(to_id.x - from_id.x)
  124. dy = abs(to_id.y - from_id.y)
  125. f = sqrt(2) - 1
  126. result = (dx < dy) ? f * dx + dy : f * dy + dx;
  127. .. _class_AStarGrid2D_constant_HEURISTIC_CHEBYSHEV:
  128. .. rst-class:: classref-enumeration-constant
  129. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_CHEBYSHEV** = ``3``
  130. The `Chebyshev heuristic <https://en.wikipedia.org/wiki/Chebyshev_distance>`__ to be used for the pathfinding using the following formula:
  131. ::
  132. dx = abs(to_id.x - from_id.x)
  133. dy = abs(to_id.y - from_id.y)
  134. result = max(dx, dy)
  135. .. _class_AStarGrid2D_constant_HEURISTIC_MAX:
  136. .. rst-class:: classref-enumeration-constant
  137. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MAX** = ``4``
  138. Represents the size of the :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` enum.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _enum_AStarGrid2D_DiagonalMode:
  142. .. rst-class:: classref-enumeration
  143. enum **DiagonalMode**:
  144. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_ALWAYS:
  145. .. rst-class:: classref-enumeration-constant
  146. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ALWAYS** = ``0``
  147. The pathfinding algorithm will ignore solid neighbors around the target cell and allow passing using diagonals.
  148. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_NEVER:
  149. .. rst-class:: classref-enumeration-constant
  150. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_NEVER** = ``1``
  151. The pathfinding algorithm will ignore all diagonals and the way will be always orthogonal.
  152. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE:
  153. .. rst-class:: classref-enumeration-constant
  154. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE** = ``2``
  155. The pathfinding algorithm will avoid using diagonals if at least two obstacles have been placed around the neighboring cells of the specific path segment.
  156. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES:
  157. .. rst-class:: classref-enumeration-constant
  158. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES** = ``3``
  159. The pathfinding algorithm will avoid using diagonals if any obstacle has been placed around the neighboring cells of the specific path segment.
  160. .. _class_AStarGrid2D_constant_DIAGONAL_MODE_MAX:
  161. .. rst-class:: classref-enumeration-constant
  162. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_MAX** = ``4``
  163. Represents the size of the :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` enum.
  164. .. rst-class:: classref-section-separator
  165. ----
  166. .. rst-class:: classref-descriptions-group
  167. Property Descriptions
  168. ---------------------
  169. .. _class_AStarGrid2D_property_cell_size:
  170. .. rst-class:: classref-property
  171. :ref:`Vector2<class_Vector2>` **cell_size** = ``Vector2(1, 1)``
  172. .. rst-class:: classref-property-setget
  173. - void **set_cell_size** **(** :ref:`Vector2<class_Vector2>` value **)**
  174. - :ref:`Vector2<class_Vector2>` **get_cell_size** **(** **)**
  175. 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.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_AStarGrid2D_property_default_compute_heuristic:
  179. .. rst-class:: classref-property
  180. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_compute_heuristic** = ``0``
  181. .. rst-class:: classref-property-setget
  182. - void **set_default_compute_heuristic** **(** :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` value **)**
  183. - :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_compute_heuristic** **(** **)**
  184. 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.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_AStarGrid2D_property_default_estimate_heuristic:
  188. .. rst-class:: classref-property
  189. :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_estimate_heuristic** = ``0``
  190. .. rst-class:: classref-property-setget
  191. - void **set_default_estimate_heuristic** **(** :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` value **)**
  192. - :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_estimate_heuristic** **(** **)**
  193. 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.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_AStarGrid2D_property_diagonal_mode:
  197. .. rst-class:: classref-property
  198. :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **diagonal_mode** = ``0``
  199. .. rst-class:: classref-property-setget
  200. - void **set_diagonal_mode** **(** :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` value **)**
  201. - :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **get_diagonal_mode** **(** **)**
  202. A specific :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` mode which will force the path to avoid or accept the specified diagonals.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_AStarGrid2D_property_jumping_enabled:
  206. .. rst-class:: classref-property
  207. :ref:`bool<class_bool>` **jumping_enabled** = ``false``
  208. .. rst-class:: classref-property-setget
  209. - void **set_jumping_enabled** **(** :ref:`bool<class_bool>` value **)**
  210. - :ref:`bool<class_bool>` **is_jumping_enabled** **(** **)**
  211. Enables or disables jumping to skip up the intermediate points and speeds up the searching algorithm.
  212. \ **Note:** Currently, toggling it on disables the consideration of weight scaling in pathfinding.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. _class_AStarGrid2D_property_offset:
  216. .. rst-class:: classref-property
  217. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)``
  218. .. rst-class:: classref-property-setget
  219. - void **set_offset** **(** :ref:`Vector2<class_Vector2>` value **)**
  220. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)**
  221. 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.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_AStarGrid2D_property_region:
  225. .. rst-class:: classref-property
  226. :ref:`Rect2i<class_Rect2i>` **region** = ``Rect2i(0, 0, 0, 0)``
  227. .. rst-class:: classref-property-setget
  228. - void **set_region** **(** :ref:`Rect2i<class_Rect2i>` value **)**
  229. - :ref:`Rect2i<class_Rect2i>` **get_region** **(** **)**
  230. 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.
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _class_AStarGrid2D_property_size:
  234. .. rst-class:: classref-property
  235. :ref:`Vector2i<class_Vector2i>` **size** = ``Vector2i(0, 0)``
  236. .. rst-class:: classref-property-setget
  237. - void **set_size** **(** :ref:`Vector2i<class_Vector2i>` value **)**
  238. - :ref:`Vector2i<class_Vector2i>` **get_size** **(** **)**
  239. 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.
  240. \ *Deprecated.* Use :ref:`region<class_AStarGrid2D_property_region>` instead.
  241. .. rst-class:: classref-section-separator
  242. ----
  243. .. rst-class:: classref-descriptions-group
  244. Method Descriptions
  245. -------------------
  246. .. _class_AStarGrid2D_private_method__compute_cost:
  247. .. rst-class:: classref-method
  248. :ref:`float<class_float>` **_compute_cost** **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |virtual| |const|
  249. Called when computing the cost between two connected points.
  250. Note that this function is hidden in the default **AStarGrid2D** class.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_AStarGrid2D_private_method__estimate_cost:
  254. .. rst-class:: classref-method
  255. :ref:`float<class_float>` **_estimate_cost** **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)** |virtual| |const|
  256. Called when estimating the cost between a point and the path's ending point.
  257. Note that this function is hidden in the default **AStarGrid2D** class.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_AStarGrid2D_method_clear:
  261. .. rst-class:: classref-method
  262. void **clear** **(** **)**
  263. Clears the grid and sets the :ref:`region<class_AStarGrid2D_property_region>` to ``Rect2i(0, 0, 0, 0)``.
  264. .. rst-class:: classref-item-separator
  265. ----
  266. .. _class_AStarGrid2D_method_fill_solid_region:
  267. .. rst-class:: classref-method
  268. void **fill_solid_region** **(** :ref:`Rect2i<class_Rect2i>` region, :ref:`bool<class_bool>` solid=true **)**
  269. Fills the given ``region`` on the grid with the specified value for the solid flag.
  270. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_AStarGrid2D_method_fill_weight_scale_region:
  274. .. rst-class:: classref-method
  275. void **fill_weight_scale_region** **(** :ref:`Rect2i<class_Rect2i>` region, :ref:`float<class_float>` weight_scale **)**
  276. Fills the given ``region`` on the grid with the specified value for the weight scale.
  277. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_AStarGrid2D_method_get_id_path:
  281. .. rst-class:: classref-method
  282. :ref:`Vector2i[]<class_Vector2i>` **get_id_path** **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)**
  283. 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.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_AStarGrid2D_method_get_point_path:
  287. .. rst-class:: classref-method
  288. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_point_path** **(** :ref:`Vector2i<class_Vector2i>` from_id, :ref:`Vector2i<class_Vector2i>` to_id **)**
  289. 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.
  290. \ **Note:** This method is not thread-safe. If called from a :ref:`Thread<class_Thread>`, it will return an empty :ref:`PackedVector2Array<class_PackedVector2Array>` and will print an error message.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_AStarGrid2D_method_get_point_position:
  294. .. rst-class:: classref-method
  295. :ref:`Vector2<class_Vector2>` **get_point_position** **(** :ref:`Vector2i<class_Vector2i>` id **)** |const|
  296. Returns the position of the point associated with the given ``id``.
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_AStarGrid2D_method_get_point_weight_scale:
  300. .. rst-class:: classref-method
  301. :ref:`float<class_float>` **get_point_weight_scale** **(** :ref:`Vector2i<class_Vector2i>` id **)** |const|
  302. Returns the weight scale of the point associated with the given ``id``.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_AStarGrid2D_method_is_dirty:
  306. .. rst-class:: classref-method
  307. :ref:`bool<class_bool>` **is_dirty** **(** **)** |const|
  308. Indicates that the grid parameters were changed and :ref:`update<class_AStarGrid2D_method_update>` needs to be called.
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_AStarGrid2D_method_is_in_bounds:
  312. .. rst-class:: classref-method
  313. :ref:`bool<class_bool>` **is_in_bounds** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  314. 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))``.
  315. .. rst-class:: classref-item-separator
  316. ----
  317. .. _class_AStarGrid2D_method_is_in_boundsv:
  318. .. rst-class:: classref-method
  319. :ref:`bool<class_bool>` **is_in_boundsv** **(** :ref:`Vector2i<class_Vector2i>` id **)** |const|
  320. 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)``.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_AStarGrid2D_method_is_point_solid:
  324. .. rst-class:: classref-method
  325. :ref:`bool<class_bool>` **is_point_solid** **(** :ref:`Vector2i<class_Vector2i>` id **)** |const|
  326. Returns ``true`` if a point is disabled for pathfinding. By default, all points are enabled.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_AStarGrid2D_method_set_point_solid:
  330. .. rst-class:: classref-method
  331. void **set_point_solid** **(** :ref:`Vector2i<class_Vector2i>` id, :ref:`bool<class_bool>` solid=true **)**
  332. Disables or enables the specified point for pathfinding. Useful for making an obstacle. By default, all points are enabled.
  333. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_AStarGrid2D_method_set_point_weight_scale:
  337. .. rst-class:: classref-method
  338. void **set_point_weight_scale** **(** :ref:`Vector2i<class_Vector2i>` id, :ref:`float<class_float>` weight_scale **)**
  339. 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.
  340. \ **Note:** Calling :ref:`update<class_AStarGrid2D_method_update>` is not needed after the call of this function.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_AStarGrid2D_method_update:
  344. .. rst-class:: classref-method
  345. void **update** **(** **)**
  346. 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.
  347. \ **Note:** All point data (solidity and weight scale) will be cleared.
  348. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  349. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  350. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  351. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  352. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  353. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  354. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`