Attention: Here be dragons

This is the `latest` (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

# AStar2D¶

Inherits: RefCounted < Object

An implementation of A* for finding the shortest path between two vertices on a connected graph in 2D space.

## Description¶

An implementation of the A* algorithm, used to find the shortest path between two vertices on a connected graph in 2D space.

See AStar3D for a more thorough explanation on how to use this class. AStar2D is a wrapper for AStar3D that enforces 2D coordinates.

## Methods¶

 float _compute_cost(from_id: int, to_id: int) virtual const float _estimate_cost(from_id: int, to_id: int) virtual const void add_point(id: int, position: Vector2, weight_scale: float = 1.0) bool are_points_connected(id: int, to_id: int, bidirectional: bool = true) const void clear() void connect_points(id: int, to_id: int, bidirectional: bool = true) void disconnect_points(id: int, to_id: int, bidirectional: bool = true) int get_available_point_id() const int get_closest_point(to_position: Vector2, include_disabled: bool = false) const Vector2 get_closest_position_in_segment(to_position: Vector2) const PackedInt64Array get_id_path(from_id: int, to_id: int) int get_point_capacity() const PackedInt64Array int get_point_count() const PackedInt64Array PackedVector2Array get_point_path(from_id: int, to_id: int) Vector2 get_point_position(id: int) const float get_point_weight_scale(id: int) const bool has_point(id: int) const bool is_point_disabled(id: int) const void remove_point(id: int) void reserve_space(num_nodes: int) void set_point_disabled(id: int, disabled: bool = true) void set_point_position(id: int, position: Vector2) void set_point_weight_scale(id: int, weight_scale: float)

## Method Descriptions¶

float _compute_cost(from_id: int, to_id: int) virtual const

Called when computing the cost between two connected points.

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

float _estimate_cost(from_id: int, to_id: int) virtual const

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(id: int, position: Vector2, weight_scale: float = 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 0.0 or greater.

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