- Home /
A* Pathfinding, don't allow obstacle to block target.
Hi there,
I have the A* pathfinding asset, and I am wondering if it's possible to, when placing obstacles down, that when you try to place one, if it blocks the path to the target, then it won't let you place it down.
Is there a function, or variable for this?
Thank you.
Answer by HarshadK · Sep 22, 2014 at 08:09 AM
I haven't come across a method that will allow you to do it but you can use Path.vectorPath to get the path. The document states that:
Path.vectorPath is a Vector3 list which holds the path, this list will be modified if any smoothing is used, it is the recommended way to get a path.
Once you have the path you can check if the obstacle you are trying to put lies on that path. If it lies just do not allow to place that obstacle there.
@Harshadk It's not that I want to prevent placing an object on the path, I want to prevent placing an object on the path IF it blocks all paths to the target. So if I place an obstacle down and now all paths are blocked to the target, this is what I want to prevent.
In that case add a node of obstacle at desired location in the tree and make the A* compute a path. If there is no path possible then do not place obstacle at the desired place. This will require you to modify the nodes at runtime.
Your answer
![](https://koobas.hobune.stream/wayback/20220613163522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Evade a Collider on Vector3.forward 3 Answers
A* Pathfinding Project Problem with Obstacles 2 Answers
A* Algorithm Node Grid Generation 2 Answers