Hi, Aron!
I am using the awesome ITraversalProvider interface in my turn-based game. So far it’s great help.
However, when I am trying to search for a path to a walkable node that is blocked via ITraversalProvider, it returns an empty array. Shouldn’t it look for an alternative path instead? (to a closest walkable node on graph)
So the question is, how can I manually look for a ClosestWalkable() node on graph while still using ITraversalProvider blocking system? I love it and would like to keep the functionality.
Thank you
I’ve tried setting ABPath.calculatePartial = true, but it doesn’t work, same result (empty array)
Hi
For that you will have to also override the NNConstraint. Sorry about the potentially duplicate code there.
The reason is that the ITraversalProvider only says which nodes the agent can traverse, but it doesn’t actually change how the search for the closest node to the start and end point is being done. This is mostly due to compatibility and historical reasons though, it is not the best design.
public MyNNConstraint : PathNNConstraint {
public override bool Suitable (GraphNode node) {
if (your code here) return false;
return base.Suitable(node);
}
}
myPath.nnConstraint = new MyNNConstraint();
You will also have to set calculatePartial to true as you have already done.
I haven’t tested the above though, so I might have forgotten something. I think this should work though.
It worked!!
Just as you expected . I appreciate your help, Aron!
Also, I noticed that if I use the same constraint with GridGraph.GetNearestForce() instead of with path, it doesn’t produce the same result even though Suitable() returns false correctly during search.
Could you explain why that happens? I tired inheriting from NNConstraint instead of PathNNConstraint but results are the same.
Hi
The PathNNConstraint will do something slightly different for the end node of a path. It will find the closest node which is also reachable from the start node (as indicated by the ‘area’ field of the node, this only takes into account walkability, not any additional ITraversalProvider rules). Maybe that’s what you are seeing?