Hello, I’m using the grid graph for a simple tower defense. I’m generating a map to have walls placed randomly on the grid, when I place a wall I would like to ensure that the wall will not block the path between multiple checkpoints, but it’s not working and I would like to understand what I did wrong.
The code to ensure the wall can be placed:
public bool CanPlaceObject(Bounds bounds)
{
CheckPoint checkPoint = _checkPoints.start;
GraphUpdateObject guo = new GraphUpdateObject(bounds);
guo.modifyWalkability = true;
guo.setWalkability = false;
List<GraphNode> nodes = new List<GraphNode>();
while (checkPoint.next != null)
{
Vector2Int nodeCoord = GetCoordFromPosition(checkPoint.transform.position);
var node = _gridGraph.GetNode(nodeCoord.x, nodeCoord.y);
nodes.Add(node);
checkPoint = checkPoint.next;
}
return GraphUpdateUtilities.UpdateGraphsNoBlock(guo, nodes, true);
}
This method seems to return true even if the path is blocked.
When a wall is placed, I update the walkability of the node using this method.
public void SetWalkable(int x, int y, bool walkable)
{
_gridGraph.GetNode(x, y).Walkable = walkable;
_gridGraph.CalculateConnectionsForCellAndNeighbours(x, y);
}
For example, here is a graph that I generated:
Black dots are checkpoints, red square are unwalkable nodes. As you can see on the screenshot there are no path between both checkpoints.
When I call the method “PathUtilities.IsPathPossible” between the 2 checkpoints, it returns true but when I spawn an agent on the first checkpoint with his destination on the second checkpoint, the agent is stuck with no possible path.
Here is the graph settings:
I hope I gave you enough information to help me out.
Thanks in advance!