mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
705 lines
42 KiB
ReStructuredText
705 lines
42 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_AStarGrid2D:
|
||
|
||
AStarGrid2D
|
||
===========
|
||
|
||
**Наследует:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
Реализация A\* для поиска кратчайшего пути между двумя точками на частичной двумерной сетке.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Описание
|
||
----------------
|
||
|
||
**AStarGrid2D** — это вариант :ref:`AStar2D<class_AStar2D>`, который специализирован для частичных 2D-сеток. Он проще в использовании, поскольку не требует ручного создания точек и их соединения. Этот класс также поддерживает несколько типов эвристик, режимы для диагонального перемещения и режим прыжка для ускорения вычислений.
|
||
|
||
Чтобы использовать **AStarGrid2D**, вам нужно только задать :ref:`region<class_AStarGrid2D_property_region>` сетки, опционально задать :ref:`cell_size<class_AStarGrid2D_property_cell_size>`, а затем вызвать метод :ref:`update()<class_AStarGrid2D_method_update>`:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar_grid = AStarGrid2D.new()
|
||
astar_grid.region = Rect2i(0, 0, 32, 32)
|
||
astar_grid.cell_size = Vector2(16, 16)
|
||
astar_grid.update()
|
||
print(astar_grid.get_id_path(Vector2i(0, 0), Vector2i(3, 4))) # Prints [(0, 0), (1, 1), (2, 2), (3, 3), (3, 4)]
|
||
print(astar_grid.get_point_path(Vector2i(0, 0), Vector2i(3, 4))) # Prints [(0, 0), (16, 16), (32, 32), (48, 48), (48, 64)]
|
||
|
||
.. code-tab:: csharp
|
||
|
||
AStarGrid2D astarGrid = new AStarGrid2D();
|
||
astarGrid.Region = new Rect2I(0, 0, 32, 32);
|
||
astarGrid.CellSize = new Vector2I(16, 16);
|
||
astarGrid.Update();
|
||
GD.Print(astarGrid.GetIdPath(Vector2I.Zero, new Vector2I(3, 4))); // Prints [(0, 0), (1, 1), (2, 2), (3, 3), (3, 4)]
|
||
GD.Print(astarGrid.GetPointPath(Vector2I.Zero, new Vector2I(3, 4))); // Prints [(0, 0), (16, 16), (32, 32), (48, 48), (48, 64)]
|
||
|
||
|
||
|
||
Чтобы удалить точку из сетки поиска пути, ее необходимо сделать «сплошной» с помощью :ref:`set_point_solid()<class_AStarGrid2D_method_set_point_solid>`.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Обучающие материалы
|
||
--------------------------------------
|
||
|
||
- `Демонстрация AStarGrid2D с навигацией на основе сетки <https://godotengine.org/asset-library/asset/2723>`__
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Свойства
|
||
----------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`CellShape<enum_AStarGrid2D_CellShape>` | :ref:`cell_shape<class_AStarGrid2D_property_cell_shape>` | ``0`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`cell_size<class_AStarGrid2D_property_cell_size>` | ``Vector2(1, 1)`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_compute_heuristic<class_AStarGrid2D_property_default_compute_heuristic>` | ``0`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` | :ref:`default_estimate_heuristic<class_AStarGrid2D_property_default_estimate_heuristic>` | ``0`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` | :ref:`diagonal_mode<class_AStarGrid2D_property_diagonal_mode>` | ``0`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`jumping_enabled<class_AStarGrid2D_property_jumping_enabled>` | ``false`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AStarGrid2D_property_offset>` | ``Vector2(0, 0)`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Rect2i<class_Rect2i>` | :ref:`region<class_AStarGrid2D_property_region>` | ``Rect2i(0, 0, 0, 0)`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
| :ref:`Vector2i<class_Vector2i>` | :ref:`size<class_AStarGrid2D_property_size>` | ``Vector2i(0, 0)`` |
|
||
+----------------------------------------------------+------------------------------------------------------------------------------------------+------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Методы
|
||
------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`_estimate_cost<class_AStarGrid2D_private_method__estimate_cost>`\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, end_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`clear<class_AStarGrid2D_method_clear>`\ (\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`fill_solid_region<class_AStarGrid2D_method_fill_solid_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`, solid\: :ref:`bool<class_bool>` = true\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`fill_weight_scale_region<class_AStarGrid2D_method_fill_weight_scale_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`, weight_scale\: :ref:`float<class_float>`\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_point_data_in_region<class_AStarGrid2D_method_get_point_data_in_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_AStarGrid2D_method_get_point_position>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_point_weight_scale<class_AStarGrid2D_method_get_point_weight_scale>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_dirty<class_AStarGrid2D_method_is_dirty>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :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| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_in_boundsv<class_AStarGrid2D_method_is_in_boundsv>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_point_solid<class_AStarGrid2D_method_is_point_solid>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_point_solid<class_AStarGrid2D_method_set_point_solid>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`, solid\: :ref:`bool<class_bool>` = true\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_point_weight_scale<class_AStarGrid2D_method_set_point_weight_scale>`\ (\ id\: :ref:`Vector2i<class_Vector2i>`, weight_scale\: :ref:`float<class_float>`\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`update<class_AStarGrid2D_method_update>`\ (\ ) |
|
||
+------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Перечисления
|
||
------------------------
|
||
|
||
.. _enum_AStarGrid2D_Heuristic:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **Heuristic**: :ref:`🔗<enum_AStarGrid2D_Heuristic>`
|
||
|
||
.. _class_AStarGrid2D_constant_HEURISTIC_EUCLIDEAN:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_EUCLIDEAN** = ``0``
|
||
|
||
`Евклидова эвристика (Euclidean heuristic) <https://en.wikipedia.org/wiki/Euclidean_distance>`__, используемая для поиска пути, по следующей формуле:
|
||
|
||
::
|
||
|
||
dx = abs(to_id.x - from_id.x)
|
||
dy = abs(to_id.y - from_id.y)
|
||
result = sqrt(dx * dx + dy * dy)
|
||
|
||
\ **Примечание:** Это также внутренняя эвристика, используемая в :ref:`AStar3D<class_AStar3D>` и :ref:`AStar2D<class_AStar2D>` по умолчанию (с включением возможной координаты оси z).
|
||
|
||
.. _class_AStarGrid2D_constant_HEURISTIC_MANHATTAN:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MANHATTAN** = ``1``
|
||
|
||
`Manhattan heuristic <https://en.wikipedia.org/wiki/Taxicab_geometry>`__ для использования при поиске пути с использованием следующей формулы:
|
||
|
||
::
|
||
|
||
dx = abs(to_id.x - from_id.x)
|
||
dy = abs(to_id.y - from_id.y)
|
||
result = dx + dy
|
||
|
||
\ **Примечание:** Эта эвристика предназначена для использования с 4-сторонними ортогональными движениями, обеспечиваемыми установкой :ref:`dialog_mode<class_AStarGrid2D_property_dialog_mode>` на :ref:`DIAGONAL_MODE_NEVER<class_AStarGrid2D_constant_DIAGONAL_MODE_NEVER>`.
|
||
|
||
.. _class_AStarGrid2D_constant_HEURISTIC_OCTILE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_OCTILE** = ``2``
|
||
|
||
Эвристика Octile, используемая для поиска пути, использует следующую формулу:
|
||
|
||
::
|
||
|
||
dx = abs(to_id.x - from_id.x)
|
||
dy = abs(to_id.y - from_id.y)
|
||
f = sqrt(2) - 1
|
||
result = (dx < dy) ? f * dx + dy : f * dy + dx;
|
||
|
||
.. _class_AStarGrid2D_constant_HEURISTIC_CHEBYSHEV:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_CHEBYSHEV** = ``3``
|
||
|
||
`Chebyshev heuristic <https://en.wikipedia.org/wiki/Chebyshev_distance>`__ для использования при поиске пути с использованием следующей формулы:
|
||
|
||
::
|
||
|
||
dx = abs(to_id.x - from_id.x)
|
||
dy = abs(to_id.y - from_id.y)
|
||
result = max(dx, dy)
|
||
|
||
.. _class_AStarGrid2D_constant_HEURISTIC_MAX:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **HEURISTIC_MAX** = ``4``
|
||
|
||
Представляет размер перечисления :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _enum_AStarGrid2D_DiagonalMode:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **DiagonalMode**: :ref:`🔗<enum_AStarGrid2D_DiagonalMode>`
|
||
|
||
.. _class_AStarGrid2D_constant_DIAGONAL_MODE_ALWAYS:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ALWAYS** = ``0``
|
||
|
||
Алгоритм поиска пути будет игнорировать сплошных соседей вокруг целевой ячейки и разрешать проход по диагоналям.
|
||
|
||
.. _class_AStarGrid2D_constant_DIAGONAL_MODE_NEVER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_NEVER** = ``1``
|
||
|
||
Алгоритм поиска пути будет игнорировать все диагонали, и путь всегда будет ортогональным.
|
||
|
||
.. _class_AStarGrid2D_constant_DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_AT_LEAST_ONE_WALKABLE** = ``2``
|
||
|
||
Алгоритм поиска пути избегает использования диагоналей, если вокруг соседних ячеек определенного сегмента пути размещено не менее двух препятствий.
|
||
|
||
.. _class_AStarGrid2D_constant_DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES** = ``3``
|
||
|
||
Алгоритм поиска пути избегает использования диагоналей, если вокруг соседних ячеек определенного сегмента пути размещено какое-либо препятствие.
|
||
|
||
.. _class_AStarGrid2D_constant_DIAGONAL_MODE_MAX:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **DIAGONAL_MODE_MAX** = ``4``
|
||
|
||
Представляет размер перечисления :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _enum_AStarGrid2D_CellShape:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **CellShape**: :ref:`🔗<enum_AStarGrid2D_CellShape>`
|
||
|
||
.. _class_AStarGrid2D_constant_CELL_SHAPE_SQUARE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_SQUARE** = ``0``
|
||
|
||
Прямоугольная форма ячеек.
|
||
|
||
.. _class_AStarGrid2D_constant_CELL_SHAPE_ISOMETRIC_RIGHT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_ISOMETRIC_RIGHT** = ``1``
|
||
|
||
Форма ячейки ромба (для изометрического вида). Координаты ячейки, где горизонтальная ось идет вверх-вправо, а вертикальная — вниз-вправо.
|
||
|
||
.. _class_AStarGrid2D_constant_CELL_SHAPE_ISOMETRIC_DOWN:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_ISOMETRIC_DOWN** = ``2``
|
||
|
||
Форма ячейки ромба (для изометрического вида). Координаты ячейки, где горизонтальная ось идет вниз-вправо, а вертикальная — вниз-влево.
|
||
|
||
.. _class_AStarGrid2D_constant_CELL_SHAPE_MAX:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`CellShape<enum_AStarGrid2D_CellShape>` **CELL_SHAPE_MAX** = ``3``
|
||
|
||
Представляет размер перечисления :ref:`CellShape<enum_AStarGrid2D_CellShape>`.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описания свойств
|
||
--------------------------------
|
||
|
||
.. _class_AStarGrid2D_property_cell_shape:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`CellShape<enum_AStarGrid2D_CellShape>` **cell_shape** = ``0`` :ref:`🔗<class_AStarGrid2D_property_cell_shape>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_cell_shape**\ (\ value\: :ref:`CellShape<enum_AStarGrid2D_CellShape>`\ )
|
||
- :ref:`CellShape<enum_AStarGrid2D_CellShape>` **get_cell_shape**\ (\ )
|
||
|
||
Форма ячейки. Влияет на то, как позиции размещаются в сетке. Если изменено, необходимо вызвать :ref:`update()<class_AStarGrid2D_method_update>` перед поиском следующего пути.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_cell_size:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Vector2<class_Vector2>` **cell_size** = ``Vector2(1, 1)`` :ref:`🔗<class_AStarGrid2D_property_cell_size>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_cell_size**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
|
||
- :ref:`Vector2<class_Vector2>` **get_cell_size**\ (\ )
|
||
|
||
Размер ячейки точки, который будет применен для расчета результирующей позиции точки, возвращаемой :ref:`get_point_path()<class_AStarGrid2D_method_get_point_path>`. Если изменено, :ref:`update()<class_AStarGrid2D_method_update>` необходимо вызвать перед поиском следующего пути.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_default_compute_heuristic:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_compute_heuristic** = ``0`` :ref:`🔗<class_AStarGrid2D_property_default_compute_heuristic>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_default_compute_heuristic**\ (\ value\: :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`\ )
|
||
- :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_compute_heuristic**\ (\ )
|
||
|
||
Значение по умолчанию :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`, которое будет использоваться для расчета стоимости между двумя точками, если :ref:`_compute_cost()<class_AStarGrid2D_private_method__compute_cost>` не был переопределен.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_default_estimate_heuristic:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **default_estimate_heuristic** = ``0`` :ref:`🔗<class_AStarGrid2D_property_default_estimate_heuristic>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_default_estimate_heuristic**\ (\ value\: :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`\ )
|
||
- :ref:`Heuristic<enum_AStarGrid2D_Heuristic>` **get_default_estimate_heuristic**\ (\ )
|
||
|
||
Значение по умолчанию :ref:`Heuristic<enum_AStarGrid2D_Heuristic>`, которое будет использоваться для расчета стоимости между точкой и конечной точкой, если :ref:`_estimate_cost()<class_AStarGrid2D_private_method__estimate_cost>` не был переопределен.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_diagonal_mode:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **diagonal_mode** = ``0`` :ref:`🔗<class_AStarGrid2D_property_diagonal_mode>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_diagonal_mode**\ (\ value\: :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>`\ )
|
||
- :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>` **get_diagonal_mode**\ (\ )
|
||
|
||
Конкретный режим :ref:`DiagonalMode<enum_AStarGrid2D_DiagonalMode>`, который заставит путь избегать или принимать указанные диагонали.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_jumping_enabled:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`bool<class_bool>` **jumping_enabled** = ``false`` :ref:`🔗<class_AStarGrid2D_property_jumping_enabled>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_jumping_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
||
- :ref:`bool<class_bool>` **is_jumping_enabled**\ (\ )
|
||
|
||
Включает или отключает возможность перехода через промежуточные точки и ускоряет алгоритм поиска.
|
||
|
||
\ **Примечание:** В настоящее время включение отключает учет масштабирования веса при поиске пути.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_offset:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_AStarGrid2D_property_offset>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
|
||
- :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
|
||
|
||
Смещение сетки, которое будет применено для расчета результирующего положения точки, возвращаемого :ref:`get_point_path()<class_AStarGrid2D_method_get_point_path>`. Если изменено, :ref:`update()<class_AStarGrid2D_method_update>` необходимо вызвать перед поиском следующего пути.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_region:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Rect2i<class_Rect2i>` **region** = ``Rect2i(0, 0, 0, 0)`` :ref:`🔗<class_AStarGrid2D_property_region>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_region**\ (\ value\: :ref:`Rect2i<class_Rect2i>`\ )
|
||
- :ref:`Rect2i<class_Rect2i>` **get_region**\ (\ )
|
||
|
||
Область ячеек сетки, доступная для поиска пути. Если изменено, необходимо вызвать :ref:`update()<class_AStarGrid2D_method_update>` перед поиском следующего пути.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_property_size:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`Vector2i<class_Vector2i>` **size** = ``Vector2i(0, 0)`` :ref:`🔗<class_AStarGrid2D_property_size>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_size**\ (\ value\: :ref:`Vector2i<class_Vector2i>`\ )
|
||
- :ref:`Vector2i<class_Vector2i>` **get_size**\ (\ )
|
||
|
||
**Устарело:** Use :ref:`region<class_AStarGrid2D_property_region>` instead.
|
||
|
||
Размер сетки (количество ячеек размером :ref:`cell_size<class_AStarGrid2D_property_cell_size>` на каждой оси). Если изменено, необходимо вызвать :ref:`update()<class_AStarGrid2D_method_update>` перед поиском следующего пути.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описания метода
|
||
------------------------------
|
||
|
||
.. _class_AStarGrid2D_private_method__compute_cost:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Вызывается при вычислении стоимости между двумя соединенными точками.
|
||
|
||
Обратите внимание, что эта функция скрыта по умолчанию в классе **AStarGrid2D**.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_private_method__estimate_cost:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **_estimate_cost**\ (\ from_id\: :ref:`Vector2i<class_Vector2i>`, end_id\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |const| :ref:`🔗<class_AStarGrid2D_private_method__estimate_cost>`
|
||
|
||
Вызывается при оценке стоимости между точкой и конечной точкой пути.
|
||
|
||
Обратите внимание, что эта функция скрыта по умолчанию в классе **AStarGrid2D**.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_clear:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **clear**\ (\ ) :ref:`🔗<class_AStarGrid2D_method_clear>`
|
||
|
||
Очищает сетку и устанавливает :ref:`region<class_AStarGrid2D_property_region>` на ``Rect2i(0, 0, 0, 0)``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_fill_solid_region:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **fill_solid_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`, solid\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStarGrid2D_method_fill_solid_region>`
|
||
|
||
Заполняет указанную ``region`` на сетке указанным значением для флага сплошной заливки.
|
||
|
||
\ **Примечание:** Вызов :ref:`update()<class_AStarGrid2D_method_update>` не требуется после вызова этой функции.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_fill_weight_scale_region:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **fill_weight_scale_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStarGrid2D_method_fill_weight_scale_region>`
|
||
|
||
Заполняет указанную ``region`` на сетке указанным значением для весовой шкалы.
|
||
|
||
\ **Примечание:** Вызов :ref:`update()<class_AStarGrid2D_method_update>` не требуется после вызова этой функции.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_get_id_path:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Возвращает массив с идентификаторами точек, которые формируют путь, найденный AStar2D между заданными точками. Массив упорядочен от начальной точки до конечной точки пути.
|
||
|
||
Если нет допустимого пути к цели, а ``allow_partial_path`` равен ``true``, возвращает путь к ближайшей к цели точке, до которой можно добраться.
|
||
|
||
\ **Примечание:** Когда ``allow_partial_path`` равен ``true``, а ``to_id`` — сплошной, поиск может занять необычно много времени.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_get_point_data_in_region:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_point_data_in_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_get_point_data_in_region>`
|
||
|
||
Возвращает массив словарей с данными точек (``id``: :ref:`Vector2i<class_Vector2i>`, ``position``: :ref:`Vector2<class_Vector2>`, ``solid``: :ref:`bool<class_bool>`, ``weight_scale``: :ref:`float<class_float>`) в области .
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_get_point_path:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Возвращает массив с точками, которые находятся на пути, найденном **AStarGrid2D** между заданными точками. Массив упорядочен от начальной точки до конечной точки пути.
|
||
|
||
Если нет допустимого пути к цели, а ``allow_partial_path`` равен ``true``, возвращает путь к ближайшей к цели точке, до которой можно добраться.
|
||
|
||
\ **Примечание:** Этот метод не является потокобезопасным. При вызове из :ref:`Thread<class_Thread>` он вернет пустой массив и выведет сообщение об ошибке.
|
||
|
||
Кроме того, когда ``allow_partial_path`` равен ``true``, а ``to_id`` является сплошным, поиск может занять необычно много времени для завершения.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_get_point_position:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **get_point_position**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_get_point_position>`
|
||
|
||
Возвращает положение точки, связанной с указанным ``id``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_get_point_weight_scale:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_point_weight_scale**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_get_point_weight_scale>`
|
||
|
||
Возвращает весовую шкалу точки, связанной с указанным ``id``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_is_dirty:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_dirty**\ (\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_dirty>`
|
||
|
||
Указывает, что параметры сетки были изменены и необходимо вызвать :ref:`update()<class_AStarGrid2D_method_update>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_is_in_bounds:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
: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>`
|
||
|
||
Возвращает ``true``, если ``x`` и ``y`` являются допустимой координатой сетки (id), т. е. если она находится внутри :ref:`region<class_AStarGrid2D_property_region>`. Эквивалентно ``region.has_point(Vector2i(x, y))``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_is_in_boundsv:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_in_boundsv**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_in_boundsv>`
|
||
|
||
Возвращает ``true``, если вектор ``id`` является допустимой координатой сетки, т. е. если он находится внутри :ref:`region<class_AStarGrid2D_property_region>`. Эквивалентно ``region.has_point(id)``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_is_point_solid:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_point_solid**\ (\ id\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_AStarGrid2D_method_is_point_solid>`
|
||
|
||
Возвращает ``true``, если точка отключена для поиска пути. По умолчанию все точки включены.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_set_point_solid:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_point_solid**\ (\ id\: :ref:`Vector2i<class_Vector2i>`, solid\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStarGrid2D_method_set_point_solid>`
|
||
|
||
Отключает или включает указанную точку для поиска пути. Полезно для создания препятствия. По умолчанию включены все точки.
|
||
|
||
\ **Примечание:** Вызов :ref:`update()<class_AStarGrid2D_method_update>` не требуется после вызова этой функции.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_set_point_weight_scale:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_point_weight_scale**\ (\ id\: :ref:`Vector2i<class_Vector2i>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStarGrid2D_method_set_point_weight_scale>`
|
||
|
||
Устанавливает ``weight_scale`` для точки с заданным ``id``. ``weight_scale`` умножается на результат :ref:`_compute_cost()<class_AStarGrid2D_private_method__compute_cost>` при определении общей стоимости перемещения по сегменту от соседней точки до этой точки.
|
||
|
||
\ **Примечание:** Вызов :ref:`update()<class_AStarGrid2D_method_update>` не требуется после вызова этой функции.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStarGrid2D_method_update:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **update**\ (\ ) :ref:`🔗<class_AStarGrid2D_method_update>`
|
||
|
||
Обновляет внутреннее состояние сетки в соответствии с параметрами, чтобы подготовить ее к поиску пути. Необходимо вызывать, если параметры, такие как :ref:`region<class_AStarGrid2D_property_region>`, :ref:`cell_size<class_AStarGrid2D_property_cell_size>` или :ref:`offset<class_AStarGrid2D_property_offset>`, изменены. :ref:`is_dirty()<class_AStarGrid2D_method_is_dirty>` вернет ``true``, если это так и это необходимо вызвать.
|
||
|
||
\ **Примечание:** Все данные точек (твердость и шкала веса) будут очищены.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Этот метод обычно должен быть переопределен пользователем, чтобы иметь какой-либо эффект.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Этот метод не имеет побочных эффектов. Он не изменяет ни одну из переменных-членов экземпляра.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Этот метод принимает любое количество аргументов после описанных здесь.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Этот метод используется для создания типа.)`
|
||
.. |static| replace:: :abbr:`static (Этот метод не нуждается в вызове экземпляра, поэтому его можно вызвать напрямую, используя имя класса.)`
|
||
.. |operator| replace:: :abbr:`operator (Этот метод описывает допустимый оператор для использования с этим типом в качестве левого операнда.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Это значение является целым числом, составленным как битовая маска следующих флагов.)`
|
||
.. |void| replace:: :abbr:`void (Нет возвращаемого значения.)`
|