public Vector3[] GenerateGraphNodes()
{
Vector3[] nodes = new Vector3[width * height * depth];
int numNodes = 0;
for (int x = 0; x < depth; ++x)
{
// Start at row 1 as we are checking the tiles below before create a graph node
for (int y = 1; y < height; ++y)
{
for (int z = 0; z < width; ++z)
{
// If this tile is empty then we can create a node if a tile below exists
if (tiles[x * width * height + y * width + z] == null)
{
if (tiles[x * width * height + (y - 1) * width + z] != null)
{
// Add graph node
nodes[numNodes].X = TILESIZE * x;
nodes[numNodes].Y = TILESIZE * y;
nodes[numNodes].Z = TILESIZE * z;
++numNodes;
}
}
}
}
}
Vector3[] n = new Vector3[numNodes];
for (int i = 0; i < numNodes; ++i)
{
n = nodes;
}
return n;
}
While this works great and I have all my nodes, how can I efficiently find the closest node to an A.I. character based on its position?
The method I'm currently using is to snap the character's position to the node grid and search the entire node array for the node matching this snapped position. This is highly inefficient and I was wondering what advice you guys could give for finding the nearest node in this scenario?
For example should I be placing the nodes in a bounding volume hierarchy, or using an entirely different approach?