Click or drag to resize

AStar2DGetIdPath Method

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.

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]

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.

Namespace:  Godot
Assembly:  GodotSharp (in GodotSharp.dll) Version: 1.0.0
Syntax
C#
public int[] GetIdPath(
	int fromId,
	int toId
)

Parameters

fromId
Type: SystemInt32

[Missing <param name="fromId"/> documentation for "M:Godot.AStar2D.GetIdPath(System.Int32,System.Int32)"]

toId
Type: SystemInt32

[Missing <param name="toId"/> documentation for "M:Godot.AStar2D.GetIdPath(System.Int32,System.Int32)"]

Return Value

Type: Int32

[Missing <returns> documentation for "M:Godot.AStar2D.GetIdPath(System.Int32,System.Int32)"]

See Also