mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-04 10:09:56 +03:00
596 lines
32 KiB
ReStructuredText
596 lines
32 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. _class_AStar2D:
|
|
|
|
AStar2D
|
|
=======
|
|
|
|
**Hereda:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
|
|
|
Una implementación de A\* para encontrar el camino más corto entre dos vértices en un grafo conectado en un espacio 2D.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Descripción
|
|
----------------------
|
|
|
|
Una implementación del algoritmo A\*, utilizado para encontrar el camino más corto entre dos vértices en un grafo conectado en un espacio 2D.
|
|
|
|
Consulta :ref:`AStar3D<class_AStar3D>` para obtener una explicación más detallada sobre cómo usar esta clase. **AStar2D** es un envoltorio para :ref:`AStar3D<class_AStar3D>` que aplica coordenadas 2D.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Tutoriales
|
|
--------------------
|
|
|
|
- `Demo de Navegación basada en cuadrícula con AStarGrid2D <https://godotengine.org/asset-library/asset/2723>`__
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Propiedades
|
|
----------------------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------+--------------------------------------------------------------------------------+-----------+
|
|
| :ref:`bool<class_bool>` | :ref:`neighbor_filter_enabled<class_AStar2D_property_neighbor_filter_enabled>` | ``false`` |
|
|
+-------------------------+--------------------------------------------------------------------------------+-----------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Métodos
|
|
--------------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`_compute_cost<class_AStar2D_private_method__compute_cost>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`_estimate_cost<class_AStar2D_private_method__estimate_cost>`\ (\ from_id\: :ref:`int<class_int>`, end_id\: :ref:`int<class_int>`\ ) |virtual| |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`_filter_neighbor<class_AStar2D_private_method__filter_neighbor>`\ (\ from_id\: :ref:`int<class_int>`, neighbor_id\: :ref:`int<class_int>`\ ) |virtual| |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`add_point<class_AStar2D_method_add_point>`\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`, weight_scale\: :ref:`float<class_float>` = 1.0\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`are_points_connected<class_AStar2D_method_are_points_connected>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`clear<class_AStar2D_method_clear>`\ (\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`connect_points<class_AStar2D_method_connect_points>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`disconnect_points<class_AStar2D_method_disconnect_points>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_available_point_id<class_AStar2D_method_get_available_point_id>`\ (\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_closest_point<class_AStar2D_method_get_closest_point>`\ (\ to_position\: :ref:`Vector2<class_Vector2>`, include_disabled\: :ref:`bool<class_bool>` = false\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector2<class_Vector2>` | :ref:`get_closest_position_in_segment<class_AStar2D_method_get_closest_position_in_segment>`\ (\ to_position\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_id_path<class_AStar2D_method_get_id_path>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_point_capacity<class_AStar2D_method_get_point_capacity>`\ (\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_point_connections<class_AStar2D_method_get_point_connections>`\ (\ id\: :ref:`int<class_int>`\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_point_count<class_AStar2D_method_get_point_count>`\ (\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_point_ids<class_AStar2D_method_get_point_ids>`\ (\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_point_path<class_AStar2D_method_get_point_path>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector2<class_Vector2>` | :ref:`get_point_position<class_AStar2D_method_get_point_position>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_point_weight_scale<class_AStar2D_method_get_point_weight_scale>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`has_point<class_AStar2D_method_has_point>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`is_point_disabled<class_AStar2D_method_is_point_disabled>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`remove_point<class_AStar2D_method_remove_point>`\ (\ id\: :ref:`int<class_int>`\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`reserve_space<class_AStar2D_method_reserve_space>`\ (\ num_nodes\: :ref:`int<class_int>`\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`set_point_disabled<class_AStar2D_method_set_point_disabled>`\ (\ id\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>` = true\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`set_point_position<class_AStar2D_method_set_point_position>`\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`set_point_weight_scale<class_AStar2D_method_set_point_weight_scale>`\ (\ id\: :ref:`int<class_int>`, weight_scale\: :ref:`float<class_float>`\ ) |
|
|
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Descripciones de Propiedades
|
|
--------------------------------------------------------
|
|
|
|
.. _class_AStar2D_property_neighbor_filter_enabled:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`bool<class_bool>` **neighbor_filter_enabled** = ``false`` :ref:`🔗<class_AStar2D_property_neighbor_filter_enabled>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_neighbor_filter_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
|
|
- :ref:`bool<class_bool>` **is_neighbor_filter_enabled**\ (\ )
|
|
|
|
Si es ``true``, habilita el filtrado de vecinos a través de :ref:`_filter_neighbor()<class_AStar2D_private_method__filter_neighbor>`.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Descripciones de Métodos
|
|
------------------------------------------------
|
|
|
|
.. _class_AStar2D_private_method__compute_cost:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **_compute_cost**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| :ref:`🔗<class_AStar2D_private_method__compute_cost>`
|
|
|
|
Llamado al calcular el coste entre dos puntos conectados.
|
|
|
|
Ten en cuenta que esta función está oculta en la clase **AStar2D** por defecto.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_private_method__estimate_cost:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **_estimate_cost**\ (\ from_id\: :ref:`int<class_int>`, end_id\: :ref:`int<class_int>`\ ) |virtual| |const| :ref:`🔗<class_AStar2D_private_method__estimate_cost>`
|
|
|
|
Se llama cuando se calcula el coste entre un punto y punto final de un trayecto.
|
|
|
|
Nota que esta función está oculta en la clase **AStar2D** por defecto.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_private_method__filter_neighbor:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **_filter_neighbor**\ (\ from_id\: :ref:`int<class_int>`, neighbor_id\: :ref:`int<class_int>`\ ) |virtual| |const| :ref:`🔗<class_AStar2D_private_method__filter_neighbor>`
|
|
|
|
Llamado cuando un vecino entra en el procesamiento y si :ref:`neighbor_filter_enabled<class_AStar2D_property_neighbor_filter_enabled>` es ``true``. Si se devuelve ``true``, el punto no se procesará.
|
|
|
|
Ten en cuenta que esta función está oculta en la clase **AStar2D** por defecto.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_add_point:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **add_point**\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`, weight_scale\: :ref:`float<class_float>` = 1.0\ ) :ref:`🔗<class_AStar2D_method_add_point>`
|
|
|
|
Adds a new point at the given position with the given identifier. The ``id`` must be 0 or larger, and the ``weight_scale`` must be 0.0 or greater.
|
|
|
|
The ``weight_scale`` is multiplied by the result of :ref:`_compute_cost()<class_AStar2D_private_method__compute_cost>` when determining the overall cost of traveling across a segment from a neighboring point to this point. Thus, all else being equal, the algorithm prefers points with lower ``weight_scale``\ s to form a path.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var astar = AStar2D.new()
|
|
astar.add_point(1, Vector2(1, 0), 4) # Adds the point (1, 0) with weight_scale 4 and id 1
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var astar = new AStar2D();
|
|
astar.AddPoint(1, new Vector2(1, 0), 4); // Adds the point (1, 0) with weight_scale 4 and id 1
|
|
|
|
|
|
|
|
If there already exists a point for the given ``id``, its position and weight scale are updated to the given values.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_are_points_connected:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **are_points_connected**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |const| :ref:`🔗<class_AStar2D_method_are_points_connected>`
|
|
|
|
Devuelve si existe una conexión/segmento entre los puntos dados. Si ``bidirectional`` es ``false``, devuelve si el movimiento desde ``id`` a ``to_id`` es posible a través de este segmento.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_clear:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **clear**\ (\ ) :ref:`🔗<class_AStar2D_method_clear>`
|
|
|
|
Limpia todos los puntos y segmentos.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_connect_points:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **connect_points**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar2D_method_connect_points>`
|
|
|
|
Creates a segment between the given points. If ``bidirectional`` is ``false``, only movement from ``id`` to ``to_id`` is allowed, not the reverse direction.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var astar = AStar2D.new()
|
|
astar.add_point(1, Vector2(1, 1))
|
|
astar.add_point(2, Vector2(0, 5))
|
|
astar.connect_points(1, 2, false)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var astar = new AStar2D();
|
|
astar.AddPoint(1, new Vector2(1, 1));
|
|
astar.AddPoint(2, new Vector2(0, 5));
|
|
astar.ConnectPoints(1, 2, false);
|
|
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_disconnect_points:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **disconnect_points**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar2D_method_disconnect_points>`
|
|
|
|
Elimina el segmento entre los puntos dados. Si ``bidirectional`` es ``false``, solo el movimiento desde ``id`` a ``to_id`` se impide, y un segmento unidireccional posiblemente permanece.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_available_point_id:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_available_point_id**\ (\ ) |const| :ref:`🔗<class_AStar2D_method_get_available_point_id>`
|
|
|
|
Devuelve el punto de Ide proximo disponible con ningun punto asociado a el.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_closest_point:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_closest_point**\ (\ to_position\: :ref:`Vector2<class_Vector2>`, include_disabled\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_AStar2D_method_get_closest_point>`
|
|
|
|
Devuelve el ID del punto más cercano a ``to_position``, opcionalmente teniendo en cuenta los puntos desactivados. Devuelve ``-1`` si no hay puntos en el grupo de puntos.
|
|
|
|
\ **Nota:** Si varios puntos son los más cercanos a ``to_position``, se devolverá el que tenga el ID más pequeño, lo que garantiza un resultado determinista.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_closest_position_in_segment:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector2<class_Vector2>` **get_closest_position_in_segment**\ (\ to_position\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_AStar2D_method_get_closest_position_in_segment>`
|
|
|
|
Returns the closest position to ``to_position`` that resides inside a segment between two connected points.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var astar = AStar2D.new()
|
|
astar.add_point(1, Vector2(0, 0))
|
|
astar.add_point(2, Vector2(0, 5))
|
|
astar.connect_points(1, 2)
|
|
var res = astar.get_closest_position_in_segment(Vector2(3, 3)) # Returns (0, 3)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var astar = new AStar2D();
|
|
astar.AddPoint(1, new Vector2(0, 0));
|
|
astar.AddPoint(2, new Vector2(0, 5));
|
|
astar.ConnectPoints(1, 2);
|
|
Vector2 res = astar.GetClosestPositionInSegment(new Vector2(3, 3)); // Returns (0, 3)
|
|
|
|
|
|
|
|
The result is in the segment that goes from ``y = 0`` to ``y = 5``. It's the closest position in the segment to the given point.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_id_path:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_id_path**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStar2D_method_get_id_path>`
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
\ **Note:** When ``allow_partial_path`` is ``true`` and ``to_id`` is disabled the search may take an unusually long time to finish.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var astar = AStar2D.new()
|
|
astar.add_point(1, Vector2(0, 0))
|
|
astar.add_point(2, Vector2(0, 1), 1) # Default weight is 1
|
|
astar.add_point(3, Vector2(1, 1))
|
|
astar.add_point(4, Vector2(2, 0))
|
|
|
|
astar.connect_points(1, 2, false)
|
|
astar.connect_points(2, 3, false)
|
|
astar.connect_points(4, 3, false)
|
|
astar.connect_points(1, 4, false)
|
|
|
|
var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var astar = new AStar2D();
|
|
astar.AddPoint(1, new Vector2(0, 0));
|
|
astar.AddPoint(2, new Vector2(0, 1), 1); // Default weight is 1
|
|
astar.AddPoint(3, new Vector2(1, 1));
|
|
astar.AddPoint(4, new Vector2(2, 0));
|
|
|
|
astar.ConnectPoints(1, 2, false);
|
|
astar.ConnectPoints(2, 3, false);
|
|
astar.ConnectPoints(4, 3, false);
|
|
astar.ConnectPoints(1, 4, false);
|
|
long[] res = astar.GetIdPath(1, 3); // Returns [1, 2, 3]
|
|
|
|
|
|
|
|
If you change the 2nd point's weight to 3, then the result will be ``[1, 4, 3]`` instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_capacity:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_point_capacity**\ (\ ) |const| :ref:`🔗<class_AStar2D_method_get_point_capacity>`
|
|
|
|
Devuelve la capacidad de la estructura que respalda los puntos, útil en conjunto con :ref:`reserve_space()<class_AStar2D_method_reserve_space>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_connections:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_point_connections**\ (\ id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar2D_method_get_point_connections>`
|
|
|
|
Returns an array with the IDs of the points that form the connection with the given point.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var astar = AStar2D.new()
|
|
astar.add_point(1, Vector2(0, 0))
|
|
astar.add_point(2, Vector2(0, 1))
|
|
astar.add_point(3, Vector2(1, 1))
|
|
astar.add_point(4, Vector2(2, 0))
|
|
|
|
astar.connect_points(1, 2, true)
|
|
astar.connect_points(1, 3, true)
|
|
|
|
var neighbors = astar.get_point_connections(1) # Returns [2, 3]
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var astar = new AStar2D();
|
|
astar.AddPoint(1, new Vector2(0, 0));
|
|
astar.AddPoint(2, new Vector2(0, 1));
|
|
astar.AddPoint(3, new Vector2(1, 1));
|
|
astar.AddPoint(4, new Vector2(2, 0));
|
|
|
|
astar.ConnectPoints(1, 2, true);
|
|
astar.ConnectPoints(1, 3, true);
|
|
|
|
long[] neighbors = astar.GetPointConnections(1); // Returns [2, 3]
|
|
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_count:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_point_count**\ (\ ) |const| :ref:`🔗<class_AStar2D_method_get_point_count>`
|
|
|
|
Devuelve el numero de puntos actualmente en el grupo(pool) de puntos.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_ids:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_point_ids**\ (\ ) :ref:`🔗<class_AStar2D_method_get_point_ids>`
|
|
|
|
Devuelve un array de todos los ID de los puntos.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_path:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`PackedVector2Array<class_PackedVector2Array>` **get_point_path**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStar2D_method_get_point_path>`
|
|
|
|
Devuelve un array con los puntos que están en la ruta encontrada por AStar2D entre los puntos dados. El array se ordena desde el punto de inicio hasta el punto final de la ruta.
|
|
|
|
Si no hay una ruta válida al destino, y ``allow_partial_path`` es ``true``, devuelve una ruta al punto más cercano al destino que se puede alcanzar.
|
|
|
|
\ **Nota:** Este método no es seguro para hilos; solo se puede usar desde un único :ref:`Thread<class_Thread>` a la vez. Considera usar :ref:`Mutex<class_Mutex>` para asegurar el acceso exclusivo a un hilo para evitar condiciones de carrera.
|
|
|
|
Adicionalmente, cuando ``allow_partial_path`` es ``true`` y ``to_id`` está deshabilitado, la búsqueda puede tardar un tiempo inusualmente largo en finalizar.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_position:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector2<class_Vector2>` **get_point_position**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar2D_method_get_point_position>`
|
|
|
|
Devuelve la posición del punto asociado con el ``id`` dado.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_get_point_weight_scale:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **get_point_weight_scale**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar2D_method_get_point_weight_scale>`
|
|
|
|
Devuelve la escala de peso del punto asociado con el ``id`` dado.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_has_point:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **has_point**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar2D_method_has_point>`
|
|
|
|
Devuelve si existe un punto asociado con el ``id`` dado.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_is_point_disabled:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **is_point_disabled**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar2D_method_is_point_disabled>`
|
|
|
|
Devuelve si un punto esta deshabilitado or no para el buscador de rutas. Por defecto, todos los puntos estan habilitados.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_remove_point:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **remove_point**\ (\ id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar2D_method_remove_point>`
|
|
|
|
Elimina el punto asociado con el ``id`` dado del grupo de puntos.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_reserve_space:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **reserve_space**\ (\ num_nodes\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar2D_method_reserve_space>`
|
|
|
|
Reserva espacio internamente para ``num_nodes`` puntos. Útil si vas a añadir un número grande conocido de puntos a la vez, como puntos en una cuadrícula.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_set_point_disabled:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **set_point_disabled**\ (\ id\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar2D_method_set_point_disabled>`
|
|
|
|
Deshabilita o habilita el punto especificado para el buscador de rutas. Util para crear obstaculos temporales.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_set_point_position:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **set_point_position**\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_AStar2D_method_set_point_position>`
|
|
|
|
Establece la ``position`` para el punto con el ``id`` dado.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AStar2D_method_set_point_weight_scale:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **set_point_weight_scale**\ (\ id\: :ref:`int<class_int>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStar2D_method_set_point_weight_scale>`
|
|
|
|
Establece el ``weight_scale`` para el punto con el ``id`` dado. El ``weight_scale`` se multiplica por el resultado de :ref:`_compute_cost()<class_AStar2D_private_method__compute_cost>` al determinar el coste total de viajar a través de un segmento desde un punto vecino a este punto.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (Normalmente, este método debería ser sobreescrito por el usuario para que tenga algún efecto.)`
|
|
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
|
.. |const| replace:: :abbr:`const (Este método no tiene efectos secundarios. No modifica ninguna de las variables miembro de la instancia.)`
|
|
.. |vararg| replace:: :abbr:`vararg (Este método permite agregar cualquier número de argumentos después de los descritos aquí.)`
|
|
.. |constructor| replace:: :abbr:`constructor (Este método se utiliza para construir un tipo.)`
|
|
.. |static| replace:: :abbr:`static (Este método no necesita una instancia para ser llamado, por lo que puede llamarse directamente utilizando el nombre de la clase.)`
|
|
.. |operator| replace:: :abbr:`operator (Este método describe un operador válido para usar con este tipo como operando izquierdo.)`
|
|
.. |bitfield| replace:: :abbr:`BitField (Este valor es un entero compuesto como una máscara de bits de las siguientes banderas.)`
|
|
.. |void| replace:: :abbr:`void (Sin valor de retorno.)`
|