How would you get all the units that are currently sat within the borders of a grid?
I’m activating the grid with a trigger, I need to get all enemies and players that sit within the grid area and then lock them into place. How should I approach this?
Exactly what do you want to detect?
If the characters are just inside the bounding box of the grid or if they are on a walkable node?
I would love to know how to check if a point is on the grid graph. Is there a simple check for this?
Hi there, i wanted to know how to check if characters are within the bounding box area of the gridx i currently have a check to see if the closeat node to a players position is within that active grid froma certain distance.
I also would live to know how you can store what unit is currently on a grid piece or check what class of object is currently at the position of a node. Ive set up my own systems but i would like to know your approach to this
The most accurate way to to (1) is
var grid = AstarPath.active.data.gridGraph;
var localPoint = grid.transform.InverseTransform(transform.position);
// The height of a grid graph is not really well defined, use 100 as an example here
var gridHeight = 100;
var gridSize = new Vector3(grid.width, gridHeight, grid.depth);
bool isInsideGraph = new Bounds(gridSize*0.5f, gridSize).Contains(localPoint);
As for (2). There is no built-in way to do this. However you can get the closest node to each unit with the AstarPath.active.GetNearest method.