I am working on a tower defense where you can build the towers on the path of the creeps. When I build a tower I set the nodes walkability to false so the creeps cannot walk through the tower. When I sell the tower and update the nodes to walkability = true. The graph does not update and allow the creeps to walk along those specific nodes. I tried adding the penalty also to 0. But it still does not work when I sell the tower. IT DOES WORK however when the creep detects that the path is blocked to the waypoint and the creep destroys the tower(s) around it. Should I do a scan after each time you sell a tower? (slows down play) Or is there some other way?
building tower code:
//b1 is the tower
GraphUpdateObject guo = new GraphUpdateObject (bl.buildingGameObject.collider.bounds);
guo.setWalkability = false;
AstarPath.active.UpdateGraphs (guo);
selling tower code:
//hitColliders[I] is any tower within the radius
//the method used is a splash damage method
//but this radius is small so only the one tower is destroyed
//it destroys the tower but does not update the graph
if (hitColliders[i].tag == “Tower”) {
Destroy (hitColliders[i].gameObject);
GraphUpdateObject guo = new GraphUpdateObject (hitColliders[i].collider.bounds); guo.setWalkability = true;
guo.addPenalty = 0;
AstarPath.active.UpdateGraphs (guo);
}
Unit blocked code:
//same code as up there^^
//this code updates the graph and allows the units to walk through those nodes
if (hitColliders[i].tag == “Tower”) {
Destroy (hitColliders[i].gameObject);
GraphUpdateObject guo = new GraphUpdateObject (hitColliders[i].collider.bounds);
guo.setWalkability = true;
guo.addPenalty = 0;
AstarPath.active.UpdateGraphs (guo);
}