I am making a tycoon game and i have chosen to use A* Pathfinding (A* Pathfinding Project) for my AI as i found it so difficult making my own AI system. My tycoon game allows you to place down buildings and paths during runtime, so of course the A* Pathfinding grid has to be updated/scanned. So i added this piece of code “AstarPath.active.Scan();” to re scan every time i place down a path or building etc. The Pathfinding grid updated correctly, but the frame rate crumbles everytime it re-scans. Is there another way to re-scan which would hit my frame rate less, maybe scan in the general area?
1 Answer
1http://arongranberg.com/astar/docs/graph-updates.php
On this link you can see basic examples of GraphUpdateObject that you need.
For example if you just want to put in a new obstacle that you dont want to go through write something like this:
GraphUpdateObject guo = new GraphUpdateObject(obstacle.bounds);
guo.modifyWalkability = true;
guo.setWalkability = false;
Astarpath.active.UpdateGraphs(guo);
This is much more performance friendly than scanning over the whole graph again.
Thanks for the reply. I saw that yesterday but i didn't really understand it. So the "GraphUpdateObject" is used to only update the object? Then after you have assigned the new GraphUpdateObject i guess "Astarpath.active.UpdateGraphs(guo);" just tells the grid to update the object and nothing else? I think i might understand it, i'll have a go in a minute. Maybe i was oo tired yesterday or something and that's why i didn't understand it;) Thanks :D
– WaldyWell for example your meshrenderer has bounds or your collider has bouns. So for example var PathObj = new GraphUpdateObject(PathSpawned.renderer.bounds); AstarPath.active.UpdateGraphs(PathObj); But you can use your collider as well if you have one I just wrote an example. Dont forget to set those walkability properties that i did because this way you tell nothing to the graph. The nodes are still going to be walkable.
– dsadaThanks:D Got it all working and now instead of dropping to about 20 frames per a second it only drops by about 1:D Thanks again for you help, i appreciate it.
– Waldy
A* is generally used to find an efficient route between two nodes in a network - if you explain a little more why/how you are using it in your game we might be able to suggest alternatives (it's not obvious, to me at least, what part of a tycoon game needs graph analysis)
– tanoshimiWell the tycoon i am making is a Roller Coaster Tycoon inspired one. So you are able to place down rides, paths and trees. [30662-pathfinding.jpg|30662] The above picture shows paths which i have placed down in during runtime. But because i placed down a new path the Pathfinding grid will have to be re-scanned to detect the newly added paths. I would want the Pathfinding grid to update maybe pretty frequently. Sorry if i wan't clear in my answer, posted that about midnight;)
– Waldy