I may have been a bit to quick in accepting an answer in my last post.
I’m trying to dynamically tag areas of the map so that I can control the penalty when different types of units traverse the area.
I’ve created a generic GameObject and attached an AstarPath and a GraphUpdateScene to it. I then use those components to try and create tagged complex polygon areas (non-convex) that define my buildings. If I do the following…
`graphUpdateScene.points = polygonPoints;
graphUpdateScene.modifyTag = true;
graphUpdateScene.setTag = 1;
graphUpdateScene.penaltyDelta = 1000;
graphUpdateScene.resetPenaltyOnPhysics = false;
graphUpdateScene.updatePhysics = false;
graphUpdateScene.modifyWalkability = true;
graphUpdateScene.setWalkability = false;
graphUpdateScene.convex = false;
graphUpdateScene.Apply(pathfinding);`
Then I can see in the Scene view that the regions are all marked with red dots and the default ‘ground’ is marked with blue dots (I’m using a Grid Graph with “Path Debug Mode” set to “Areas”).
It looks good at this point, except those areas seem to be permanently “unwalkable”, which makes sense considering setWalkability is set to false, but if I go setWalkability = true, then the entire world is just blue dots (“Path Debug Mode” set to “Areas”)) BUT I do notice that with “Path Debug Mode” set to “Tags” I do see that those areas are of a different colour. Although the blue is almost indistinguishable from the grey, it does look like the tagged regions is working. Unfortunately no penalty seems to exist and the units can just walk right through, despite a supposed penalty value of 1000 being applied to the nodes.
Assuming it did work, I’m still a little unsure how the seeker can apply a penalty to those regions. I’m guessing I would do something like
`seeker.tagPenalties[1] = walkThroughBuildingPenalty;
seeker.StartPath(transform.position, destinationPoint, OnPathComplete);`
where 1 is the index of the tag I’ve tried to apply to those regions.
I notice that a lot of the users on the forums are using a GraphUpdateObject but it seems to only take a Bounds object and not a complex polygon. I saw there was a GraphUpdateObject.shape but apply a GraphUpdateShape didn’t seem to work either.
e.g. I tried this to with no luck. I don’t even get the tagged areas to show up with “Path Debug Mode” set to “Tags”
`GraphUpdateShape gus = new GraphUpdateShape();
gus.convex = false;
gus.points = polygonPoints;
GraphUpdateObject guo = new GraphUpdateObject(new Bounds(verticesTemp[0], new Vector3(10.0f, 0.0f, 10.0f)));
GraphUpdateObject guo = new GraphUpdateObject();
guo.shape = gus;
guo.modifyTag = true;
guo.setTag = 1;
guo.addPenalty = 10000;
guo.resetPenaltyOnPhysics = false;
guo.updatePhysics = false;
guo.modifyWalkability = true;
guo.setWalkability = false;
pathfinding.UpdateGraphs(guo);`
I’ve gotten myself thoroughly confused by this point. Any insight would be most welcome. I’ve tried to apply what’s mentioned in http://arongranberg.com/astar/docs/graph-updates.php and http://arongranberg.com/astar/docs/tags.php
Thanks.