Is it possible to get the gameobjects blocking path?

Hi,

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?

Hi

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.

1 Like

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?

image

Hi

Double check with the A* Inspector → Settings → Graph Coloring Mode that the tags are actually applied.

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?

What do you mean by “applied the tags in the A* inspector”?

Thanks for following up on this, so this is what I did:

Created the tags in the Graph:

Now the Tags do appear on my Character Seeker, so I added the penalties there:

I would expect them to now try to avoid the walls and building if an easier route is available nearby:

image
image

Despite doing so they don’t seem to put any effort into not going through the wall even when other paths are available, if I do add the wall as an obstacle

Hi

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.

See also Working with tags - A* Pathfinding Project

1 Like

thanks! I see it now, with GraphUpdateScene and the tag applied to it, they now do use breaches as I would expect, I will work on applying that node check that you mentioned on the first message.

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)
                {
                    return false;
                }
            }

            Debug.Log("Path is free of buildings");
            return true;
        }

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:

image
image

Based in the documentation I think I’m looking in the right place but I assume that penalty is just not set somehow?

1 Like

Hi

Nodes have both a fixed penalty and a tag which adds a varying penalty based on the path settings. The final penalty that is used for pathfinding is node.Penalty + seeker.tagPenalties[node.Tag].

fast and accurate, getting all the numbers now, thank you!

1 Like