Getting Node Position in a graph after finding a node with GetNearest

I was working on making a cover system for a top down grid based graph game. After I find a good candidate I call GetNearest to get the closest node to the object. But now I’d like to know what its x,y position in the Graph is so I can expand outward in the graph to find all of the walkable areas around the cover. I read the Graphnode documentation but I wasn’t clear how to get its position in the graph to do this.

So for example I might raycast to find a 3D cube that I can hide behind. I get the 3D point of the cubes position and use GetNearest to find out where it is in the Graph. Now I want to find the walkable places all around my 3D cube that I could hide behind and test each to see if the player can see me or not. So I’m just missing how to go form GetNearest to my position in the graph so I can find those other positions.

Thanks!

Hi

If you use a grid graph then the nodes are of type GridNode (which inherits from GraphNode). The GridNode has the properies XCoordinateInGrid and ZCoordinateInGrid which will give you what you want. See https://arongranberg.com/astar/docs/gridnode.html

You can also get the world space position using node.position (which can be cast to a Vector3 if you want).

Interesting thank you. I tried to cast the return of GetNearest into a gridnode but that did not work. I tried

                        GridNode node = (GridNode) AstarPath.active.GetNearest(transform.position).node;
                        GridNode node = AstarPath.active.GetNearest(transform.position).node;

but the only thing that works is

                        GraphNode node = AstarPath.active.GetNearest(transform.position).node;

I can work around it but is there a conversion I’m missing?

Thank you