Hi there. I feel like this may be an incredibly simple question, but I’ve been googling for a while now with no results.
Is there any way to retrieve what the bounds of a graph are? I have a very straightforward 2d graph built, and am just looking for a way to get a Vector 2 of the lower left and upper right corners of the graph.
It’s helpful to have bounds for things like how far the camera should pan, what constitutes “off camera” for spawning points, and the bounds of the graph would be very helpful.
Anyway like I said, hopefully this is just a simple thing that I haven’t figured out yet.
Thanks in advance!
For a grid graph (which I assume you are using) you can get the center like
// Get the first grid graph in the scene
var gg = AstarPath.active.data.gridGraph;
var center = gg.center;
The world space size can be calculated using
var size = new Vector2(gg.widthgg.nodeSize, gg.depthgg.nodeSize);
However it is a bit tricky to define a bounding box because the graph may be rotated, and an axis aligned bounding box is probably not what you want in case of weird rotations.
For spawning points you may be interested in this tutorial: https://arongranberg.com/astar/docs/wander.html
Fantastic. Digging into that now. Thanks a ton!
Ended up getting the corners with:
LLLimits = (Vector3)gg.nodes.position;
URLimits = (Vector3)gg.nodes[gg.nodes.Length - 1].position;
This may not work for every instance, but for something as simple as what I’m doing, it worked perfectly. Thanks again for a push in the right direction!