Find nearest obstacle on Grid Graph

Hi.

I just want to know Is there any method available to get nearest obstacle in Grid Graph ?

Or i need to write my own logic.

For my scenario, Obstacles are my target. So we can also say it’s possible to find nearest target ?

Thanks

Hi

You can search for the nearest unwalkable node using something like this:

var nn = NNConstraint.None;
nn.constrainWalkability = true;
nn.walkable = false;
var info = AstarPath.active.GetNearest(somePoint, nn);
var node = info.node;

Ok. we can also achieve same using multitarget path ?

No, unfortunately you cannot. Paths will only ever search walkable nodes.
You can switch to using tags instead of walkability which will make that possible, however that has some drawbacks (such as IsPathPossible not being a fast operation anymore and paths can no longer search for ‘the closest node to the target that we can actually reach’).

Ok. Then i need to find obstacle using code you suggested and if i have surrounding points of that obstacles which are my endpoints then i can pass that array of endpoints to multitarget path. This way i can reach to the boundary of obstacle.

Can i find object available on that node?

What do you mean by that?

I got nearest node which is unwalkable.
I have instantited object and i got nearest node.But i want to know which object is there on that node?

Hi

That is not something the pathfinding system knows about. It uses the Unity API to check if there are any colliders (there may be multiple) around that node. You can check for colliders yourself using the Physics API: https://docs.unity3d.com/ScriptReference/Physics.html.