Hello. I’ve been looking through the documentation and so far I haven’t found a method or utility class to accomplish what I need so I just wanted to ask what the most efficient approach might be for my implementation.
Basically, I have large GridGraph and I need to randomly place objects (think RTS style buildings) throughout the map. But I want to check that all nodes within the objects footprint are walkable. Also, I’d like to be able to scan the GridGraph for “openings” that are large enough for my object.
Any ideas or suggestions for the most efficient call(s) to do this?
I still haven’t found anything to suit my needs so any suggestions would be most welcome.
A hacky way I’ve been able to do it is by sending out a bunch of rays where my object wants to be and then calling GetNearest() many times with a new world position each time. This allows me to build an array of nodes that I can then check for walkability. It seems like there should be a more elegant way than this though. Ideally I’d like to use the object to be placed as a template and just detect all of the nodes within it’s collider.
I’ve also played with ConstantPath but it’s not working for me for some reason. I never get anything other than 0 nodes back.
`
List nodes= new List();
GridGraph gg = AstarPath.active.astarData.gridGraph;
for ( int i = 0; i < gg.nodes.Length; i++ ) {
if ( gg.nodes[i].Walkable ) nodes.Add ( gg.nodes[i] );
}
List pts = PathUtilities.GetPointsOnNodes (nodes, 100, 2);
`
The above will get all nodes in the grid graph and then calculate 100 points on those nodes which are separated by at least 2 world units (if possible). Note that they are not necessarily separated from obstacles by the same amount.