in my current project the player can build walls to stop enemies, if no route is possible the enemies will then destroy the walls, everything works perfectly and pathfinder does a good job finding any breach, the only issue is that when no path is possible the enemies don’t know which walls are blocking the path and which ones are not, so they may attack a wall that is not relevant to their goal, is there a way to see which gameobjects with a certain tag or layer (so only walls) are blocking the shortest path?
What you can do is to mark all those walls with a particular tag, instead of making the whole wall unwalkable. Then you can request a path which has a high penalty for traversing that tag. The path will then go through the wall where it is optimal. You can iterate through the nodes in the path and check if there are any walls on that node using your own code, this is nothing that the pathfinding system tracks.
Thanks Aron, that does sound like a plan, I checked the documentation and added the tags to the Pathfinder A* “Graph” then assigned a high penalty to that tag in the characters seeker, but no matter which number I put there they always try to go on a straight line across the wall even if there is a gap nearby, I’m obviously missing something else but not sure where, am I in the right place?
it doesn’t seem to be the case, everything shows the same green colour, Again, I applied the tags in the A* inspector, then applied a high penalty to each tag in the seeker inspector, is there any other step?
A* tags are not the same as unity tags. They are different concepts.
Currently, to apply a tag you’ll want a GraphUpdateScene component (see Graph Updates during Runtime - A* Pathfinding Project). Or, if you are using the beta, you can add the ‘Per Layer Modifications’ rule to the grid graph, which allows you to set tags based on the layer of the collider that the height raycast hit.
Took me a while but everything is working Aron, thanks, I would like to ask one more thing, I figured that I can use the penalty number to simplify a lot another bit of my code, as I can use the different penalties to prioritize some targets, this is what I’m currently using to see if the path is free of buildings:
public static bool IsPathFreeOfBuildings(Seeker test)
foreach (var nodes in test.GetCurrentPath().path)
if(nodes.Tag != 0)
Debug.Log("Path is free of buildings");
however the nodes.penalty is always 0, even when the tag seems to be correct, in this example tag 1 has a huge penalty, but it is always 0 in the code:
Based in the documentation I think I’m looking in the right place but I assume that penalty is just not set somehow?