GetNearest not working

I might be using it wrongly, but GetNearest seems to be getting the nearest point in the grid hex, rather than the grid node centre. I ended up with:

NNInfo foundNode = AstarPath.active.GetNearest(GetMousePoint(), NNConstraint.Default);
transform.position = (Vector3)foundNode.position;

not sure what’s wrong

Hi

The GetNearest method returns two fields, a node field and a position field. The position is the closest point on the navmesh to the query point, and the node field is the closest node. If you do want the center of the node then your way of doing it is precisely the correct way.

Thanks, I was extracting the NNInfo, not the GraphNode. Fixed it, works now

1 Like