Get nearest walkable node to a point inside an obstacle

Hi Aron!

I’m having kind of a brain fart and can’t figure out how to get the nearest walkable node to a point that is unwalkable. For instance, when a player commands my units to move to a point that is inside a building or an obstacle, I want the units to move to the nearest walkable node position instead.

I’m coding in JavaScript, so I’m assuming I need to import “Pathfinding”. Then what functions from your API am I going to need?

Specifically, how do I “know” when a node position is unwalkable? Then, how do I find the nearest node to that position that is walkable?

Thanks for any help.

Hi

Just setting the Seeker -> Start End Modifier -> End Point setting to ClosestOnNode or SnapToNode should do it without any code changes.

If you want to find the closest walkable node to a point, you can do
GraphNode node = AstarPath.active.GetNearest ( somePosition, NNConstraint.Default ); Vector3 nodePosition = (Vector3)node.position;

Thank you sir :slight_smile: I will give that a shot. Thanks for the super quick response.

Amazing. That’s exactly what I was looking for, and all I had to do was use a drop-down list – super easy. Thanks for the help Aron, you saved me a ton of time. I will mark this as answered.