AStarGrid2D¶
Inherits: RefCounted < Object
An implementation of A* for finding the shortest path between two points on a partial 2D grid.
Description¶
AStarGrid2D is a variant of AStar2D that is specialized for partial 2D grids. It is simpler to use because it doesn't require you to manually create points and connect them together. This class also supports multiple types of heuristics, modes for diagonal movement, and a jumping mode to speed up calculations.
To use AStarGrid2D, you only need to set the region of the grid, optionally set the cell_size, and then call the update method:
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)
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)
To remove a point from the pathfinding grid, it must be set as "solid" with set_point_solid.
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
_compute_cost ( Vector2i from_id, Vector2i to_id ) virtual const |
|
_estimate_cost ( Vector2i from_id, Vector2i to_id ) virtual const |
|
void |
clear ( ) |
void |
fill_solid_region ( Rect2i region, bool solid=true ) |
void |
fill_weight_scale_region ( Rect2i region, float weight_scale ) |
get_id_path ( Vector2i from_id, Vector2i to_id ) |
|
get_point_path ( Vector2i from_id, Vector2i to_id ) |
|
get_point_position ( Vector2i id ) const |
|
get_point_weight_scale ( Vector2i id ) const |
|