How to prevent this issue? (agent paths to target through diagonal nodes

I have a following issue, where my agent paths to a target that is near the nodes with high penalty:

as you can see, this is not desirable, since enemies will attack structures that seem like they are unreachable, but agents will reach them.

However if I put the target structure 1 tile away, it all works
image

The blue squares are nodes with high penalty, agent should go around them. The red small square is unwalkable node.

How would I prevent this?

These are the settings:


penalties for the agent (wall nodes on the pictures above are marked as Wall)
image

Hi

In the first case, the agent can reach a point just next to the building without walking around the wall, so that’s what it will do.

To get the other behavior, perhaps you could find the 4 adjacent axis-aligned nodes that are walkable/not inside the wall, and use a MultiTargetPath to find a path to the closest of those?