I'm writing a tower defense game in Unity, inspired by Desktop Tower Defense.
Creeps spawn on one side of the screen, and if they make it to the opposite side, the player takes damage. The board starts out unobstructed, and the player builds towers that shoot at creeps while also blocking their path. They can funnel creeps along a path by strategic placement of towers.
I have a terrain GameObject with a NavMesh, each creep has a NavMeshAgent, and each tower has a NavMeshObstacle. This works fine, the creeps go toward the goal and avoid the towers.
The problem is that the player is not allowed to block off all of the paths to the goal. If placing a tower would leave no routes open to the goal, it is not valid to place a tower there. I can detect this after the tower is placed, but I want to warn the player and prevent the placement from happening at all.
I also don't want to even briefly block the path to the goal by temporarily placing a NavMeshObstacle in an invalid position, because it might be exploitable by players by repeatedly attempting to place a tower there.
How can I predict whether placing a NavMeshObstacle will completely block a route between two paths, while NavMeshAgents are actively traversing the NavMesh?