I'm following Calneon's guide from reddit:

It is easy to setup for a grid. Just make a new node with a script that inherits from AStar2D, then:

  • For each cell on your grid, call add_point with an id (just increment an index), and position (in world space). Do this with a 2D loop (for x in size_x: for y in size_y).
  • Do your loop again, and this time for each cell you added previously, call connect_points with the id of the current cell, and the cells above, below, left, and right of it (if they exist).
  • Then simply call get_point_path or get_id_path with the start and end position, which will give you an array of positions, or an array of ids for the path.

So far, I've got this, the rect of the tilemap is looped through and added as points (I'm not worried about obstacles yet, just getting this much working) but I'm stuck with the second loop:

func astarloop():
	var ID = 0
	for y in range(tilemapsize.position.y, tilemapsize.end.y):
		for x in range(tilemapsize.position.x, tilemapsize.end.x):
			astar.add_point(ID, Vector2(x,y), 1.0)
			ID += 1
	
	ID = 0
	for y in range(tilemapsize.position.y, tilemapsize.end.y):
		for x in range(tilemapsize.position.x, tilemapsize.end.x):
			var IDpos
			IDpos = astar.get_point_position(ID)
			var left = IDpos + Vector2(-1,0)
			var right = IDpos + Vector2(1,0)
			var up = IDpos + Vector2(0,-1)
			var down = IDpos + Vector2(0,1)
			
			astar.connect_points(?,?)
			ID += 1

I honestly have no idea how to do this second part since there's no astar.get_ID(point_position). I could do everything at the same time in the first loop, but I can't connect points that don't exist and it would be a nightmare to try and add multiple points per loop whilst trying to keep track of the ID.

Why isn't there an astar.get_point_position? You assigned it in the first loop.

4 days later

@fire7side said: Why isn't there an astar.get_point_position? You assigned it in the first loop.

Thanks! I figured it out thanks to this awesome video:

a year later
2 years later

If you are simply connecting all cells in a list to their neighbors you do not need to check in a direction opposite one you have already checked. If you check for cells to the right, you don't need to check for cells on the left, and if you check for cells below you don't need to check for cells above.
That's because the connect_points method generates bidirectional connections by default, so every connection in one direction automatically includes its opposite. As you can see in the diagram below every connection will be covered if each cell connects to the one on its right and the one below it.