AStar2D

    AStar class representation that uses 2D vectors as edges.

    This is a wrapper for the class which uses 2D vectors instead of 3D vectors.

    • float _compute_cost ( from_id, int to_id ) virtual

    Called when computing the cost between two connected points.

    Note that this function is hidden in the default class.


    • _estimate_cost ( int from_id, to_id ) virtual

    Called when estimating the cost between a point and the path’s ending point.

    Note that this function is hidden in the default AStar2D class.


    • void add_point ( int id, position, float weight_scale=1.0 )

    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 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.

    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 ( id, int to_id ) const

    Returns whether there is a connection/segment between the given points.


    • void clear ( )

    Creates a segment between the given points. If bidirectional is false, only movement from to to_id is allowed, not the reverse direction.


    • void disconnect_points ( id, int to_id )

    Deletes the segment between the given points.


    • get_available_point_id ( ) const

    Returns the next available point ID with no point associated to it.


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

    Returns the ID of the closest point to to_position, optionally taking disabled points into account. Returns -1 if there are no points in the points pool.

    Note: If several points are the closest to to_position, the one with the smallest ID will be returned, ensuring a deterministic result.


    • get_closest_position_in_segment ( Vector2 to_position ) const

    Returns the closest position to to_position that resides inside a segment between two connected points.

    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.


    • get_id_path ( int from_id, to_id )

    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 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.


    • int get_point_capacity ( ) const

    Returns the capacity of the structure backing the points, useful in conjunction with .


    • get_point_connections ( int id )

    • get_point_count ( ) const

    Returns the number of points currently in the points pool.


    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.


    • Vector2 get_point_position ( id ) const

    Returns the position of the point associated with the given id.


    • float get_point_weight_scale ( id ) const

    Returns the weight scale of the point associated with the given id.


    Returns an array of all points.


    • has_point ( int id ) const

    Returns whether a point associated with the given id exists.


    • is_point_disabled ( int id ) const

    Returns whether a point is disabled or not for pathfinding. By default, all points are enabled.


    • void remove_point ( id )

    Removes the point associated with the given id from the points pool.


    • void reserve_space ( int num_nodes )

    Reserves space internally for num_nodes points, useful if you’re adding a known large number of points at once, for a grid for instance. New capacity must be greater or equals to old capacity.


    • void set_point_disabled ( id, bool disabled=true )

    Disables or enables the specified point for pathfinding. Useful for making a temporary obstacle.



    • void set_point_weight_scale ( id, float weight_scale )

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