Pathfinding for dynamic obstacles and player made blockages?

Hi I’m creating a TD in Unity 5 and need some help with my Pathfinding.

I’m using the UpdateGraphs() function to update the graph as obstacles spawns and destroys. However in my game I want the player to be able to block the minions with special towers which will force the minions to attack the “block tower” instead to get past to their destination. I want to increase the cost of my block towers and have them passable so the minions will always choose the easier path with no block towers if that is possible. Then somehow detect if there is a block tower in the path to attack it before continue to the destination.

How could I accomplish something like this in your A* implementation?

img link:

Hey there,

You want something like ;

There is blocked creep that explodes at blocking position (effects are missing right now) and destroy towers on explosion range. It’s easy with ABPath you should just check latest point in your path if it’s equal to your Target position or more elegant solution is ;

Pathfinding.Node node1 =, NNConstraint.Default).node;
Pathfinding.Node node2 =, NNConstraint.Default).node;
Pathfinding.PathUtilities.IsPathPossible (node1,node2)

, that means your creep isn’t blocked if it’s not your creep blocked at somewhere, move to that position and then you can simply attack blocking tower.

Hi and thank you for answering!

First of all sorry for not replying earlier, had to focus on some other stuff for some days but now I’m back to work on my game! :smile:

So by implementing the solution you provided I need to have the start location of the path and the end location of the path correct? The target position for the creeps will be the player character that can during any time move so the location of the “goal” for the creeps will never be static so how would I go about getting the locations for the start and end points?

And if I receive that the IsPathPossible is equal to false how do I check where the blocking is happening and how can I reference the GameObject that is blocking the path to allow me force the creeps to attack that object to get through?

I’m greatful for any help!


When you update your graph, instead of making the nodes unwalkable (e.g if the collider of the towers is in the grid graph’s collision mask) you can add a large penalty instead, that will give you desired behaviour (note that you need very large penalty values to make any difference in the pathfinding). See also