AStar2D

Inherits: Reference < Object

Representacion de la clase AStar que usa vectores 2D como lados.

Descripción

Este es un envoltorio para la clase AStar el cual usa vectores 2D en vez de 3D Vectors.

Métodos

float

_compute_cost ( int from_id, int to_id ) virtual

float

_estimate_cost ( int from_id, int to_id ) virtual

void

add_point ( int id, Vector2 position, float weight_scale=1.0 )

bool

are_points_connected ( int id, int to_id ) const

void

clear ( )

void

connect_points ( int id, int to_id, bool bidirectional=true )

void

disconnect_points ( int id, int to_id )

int

get_available_point_id ( ) const

int

get_closest_point ( Vector2 to_position, bool include_disabled=false ) const

Vector2

get_closest_position_in_segment ( Vector2 to_position ) const

PoolIntArray

get_id_path ( int from_id, int to_id )

int

get_point_capacity ( ) const

PoolIntArray

get_point_connections ( int id )

int

get_point_count ( ) const

PoolVector2Array

get_point_path ( int from_id, int to_id )

Vector2

get_point_position ( int id ) const

float

get_point_weight_scale ( int id ) const

Array

get_points ( )

bool

has_point ( int id ) const

bool

is_point_disabled ( int id ) const

void

remove_point ( int id )

void

reserve_space ( int num_nodes )

void

set_point_disabled ( int id, bool disabled=true )

void

set_point_position ( int id, Vector2 position )

void

set_point_weight_scale ( int id, float weight_scale )

Descripciones de Métodos

  • float _compute_cost ( int from_id, int to_id ) virtual

Llamado cuando se calcula el coste entre dos puntos conectados.

Nota que esta funcion esta oculta en la clase AStar2D por defecto.


  • float _estimate_cost ( int from_id, int to_id ) virtual

Llamado cuando se calcula el coste entre un punto el final de un punto de una ruta.

Nota que esta funcion esta oculta en la clase AStar2D por defecto.


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 1 or larger.

The weight_scale is multiplied by the result of _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_scales to form a path.

var astar = AStar2D.new()
astar.add_point(1, 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.


  • bool are_points_connected ( int id, int to_id ) const

Devuelve si hay una conexion/segmento entre los puntos dados.


  • void clear ( )

Limpia todos los puntos y segmentos.


  • void connect_points ( int id, int to_id, bool bidirectional=true )

Crea un segmento entre los puntos dados. Si bidirectional es false, solo el movimiento desde id a to_id es permitido, no la direccion inversa.

var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 1))
astar.add_point(2, Vector(0, 5))
astar.connect_points(1, 2, false)

  • void disconnect_points ( int id, int to_id )

Elimina el segmento entre los puntos dados.


  • int get_available_point_id ( ) const

Devuelve el punto de Ide proximo disponible con ningun punto asociado a el.


  • int get_closest_point ( Vector2 to_position, bool include_disabled=false ) const

Devuelve el ID del punto mas cercano a to_position, opcionalmente tomando puntos deshabilitados en cuenta. Devuelve -1 si no hay puntos el grupo(pool) de puntos.

Nota: Si varios puntos son los más cercanos a to_position, el pundo con el menor ID será devuelto, asegurando un resultado deterministico.


  • Vector2 get_closest_position_in_segment ( Vector2 to_position ) const

Devuelve el punto mas cercano a to_position que reside dentro de un segmento entre dos puntos conectados.

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)) # Devuelve (0, 3)

El resultado esta dentro del segmento que van desde y = 0 a y = 5. Es la posicion mas cercana en el segmento al punto dado.


Devuelve un array con los IDs de los puntos que forman la ruta encontrada por AStar2D entre los puntos dados. El array es ordenado desde el punto inicial al punto final de la ruta.

var astar = AStar2D.new()
astar.add_point(1, Vector2(0,0))
astar.add_point(2, Vertor2(0, 1), 1) # Por defecto el peso es 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) # Devuelve [1, 2, 3]

Si tu cambias el peso del segundo punto a 3, entonces el resultado sera [1, 4, 3], porque ahora aunque la distancia es mayor, cuesta menos ir a traves del punto 4 que des punto 2.


  • int get_point_capacity ( ) const

Devuelve la capacidad de la estructura que respalda los puntos, usado junto con reserve_space.


Devuelve un array con los IDs de los puntos que forman la conexion con los puntos dados.

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 vecinos = astar.get_point_connections(1) # Devuelve [2, 3]

  • int get_point_count ( ) const

Devuelve el numero de puntos actualmente en el grupo(pool) de puntos.


Returns an array with the points that are in the path found by AStar2D between the given points. The array is ordered from the starting point to the ending point of the path.

Note: This method is not thread-safe. If called from a Thread, it will return an empty PoolVector2Array and will print an error message.


Devuelve la posicion del punto asociado con el id dado.


  • float get_point_weight_scale ( int id ) const

Devuelve el peso del punto asociado con el id dado.


Devuelve un array con todos los puntos.


Devuelve si un punto asociado con el id existe.


  • bool is_point_disabled ( int id ) const

Devuelve si un punto esta deshabilitado or no para el buscador de rutas. Por defecto, todos los puntos estan habilitados.


  • void remove_point ( int id )

Elimina el punto asociado con el id dado del grupo(pool) de puntos.


  • void reserve_space ( int num_nodes )

Espacio de reserva interna para puntos num_nodes, util si tu estas añadiendo un gran numero de puntos a la vez, para un grid por ejemplo. Las nuevas capacidades debes ser mayores o iguales que la anterior capacidad.


  • void set_point_disabled ( int id, bool disabled=true )

Deshabilita o habilita el punto especificado para el buscador de rutas. Util para crear obstaculos temporales.


  • void set_point_position ( int id, Vector2 position )

Coloca la position para el punto con el id dado.


  • void set_point_weight_scale ( int id, float weight_scale )

Sets the weight_scale for the point with the given id. The weight_scale is multiplied by the result of _compute_cost when determining the overall cost of traveling across a segment from a neighboring point to this point.