I am having problem understanding the new AStar node

I want to translate this grid to AStar

``````var map = [
[1,1,1,1,1,1],
[1,0,0,0,0,1],
[1,1,1,1,0,1],
[1,0,0,0,0,1],
[1,0,1,1,1,1],
[1,0,0,0,0,1],
[1,1,1,1,1,1]]
``````

1 = Not walkable
0 = Walkable

I want to to find the path from map[1][1] to map[5][4] .
I assume that if every cell has its on index starting from 0, it could be:

``````print(get_id_path(7,35))
``````
in Engine

I think you have to add every cell to the graph and tell what connections are. There is not much concept of a grid. Otherwise it sounds better to use the `Navigation` node if you plan to do that on a Tilemap.

At the moment I don't really see the point of using the AStar class in tile-based games, especially with big grids, because if you use a TileMap, pathfinding is already provided by the Navigation node. I'd be curious to know why you need it :)

This is the only info I can find on the AStar node: https://www.facebook.com/photo.php?fbid=1135019413259317&set=gm.839357099534219&type=3

The one they added isn't limited to 2D grids. But as a trade-off, you have to connect each point manually. So what you can do is make a function that traverses your map variable with a double for loop, then adds the point if it equals 0. Then traverse it again to check each neighbor and connect them to the point if they are equal to 0.

It might be helpful to name each point as the row*width+column when adding the point, so something like this: `as.add_point(x*width+y, Vector3(x,y,0))`

by (846 points)

Maybe my math is bad but wont `x*width+y` cause problems when the width is less than total number of rows? I tested it with 1 & 2 and indeed it does cause some issues.

Remember that indexes are zero-based. So in a 2x2 grid (so width = 2), the top left is `(0,0)` so `x*width+y = 0*2+0=0`. Top right is `(0,1)` so `0*2+1 = 1`. Bottom left is `(1,0)` so `1*2+0=2`. And lastly, bottom right is `(1,1)` so `1*2+1=3`. So the indexes of the grid are 0,1,2,3 just as they should be.

Or if you use a 2x1 grid (so width = 1), the top is `(0,0)` so `0*1+0 = 0`, and the bottom is `(1,0)` so `1*1+0=1`.