How should enemies target things with pathfinding (with A*), that may or may not be accessible, but are always obstacles,
So some quick information:
I have enemies
I have targets (buildings, players)
I have obstacles (walls etc)
I have areas of my map that are inaccessible
I have a bottleneck, that will be likely be filled with a building / obstacle
Enemies can target buildings and players
Enemies should treat buildings as obstacles and pathfind around them
So my problem is, I can't have a building as a target if it is also an obstacle. I am using the A* pathfinding to determine if a path is possible:
private bool isTargetAccessible(Transform targettedTransform)
{
GraphNode a = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
GraphNode b = AstarPath.active.GetNearest(targettedTransform.position, NNConstraint.Default).node;
if (Pathfinding.PathUtilities.IsPathPossible(a, b))
{
return true;
}
return false;
}
In some cases, buildings will be on inaccessible parts of my map (eg up high on a wall, with no path to it). However in other cases the building will be in a bottleneck, that should mean it is targetted.
So any ideas on how I can
make my buildings obstacles
not able to be passed through
still make them able to be targeted, but only if they are accessible
Eg how can I differentiate between can access and is able to target vs cannot access and is not able to target?
Your answer
![](https://koobas.hobune.stream/wayback/20220613034209im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to know which point that AI picked to move to? (A* Pathfinding) 0 Answers
A* pathfinging problem 0 Answers
A* finding nearest Object 0 Answers
Astar movement implementation not working properly 0 Answers
astar pathfinding with groups 0 Answers