- Home /
Question by
WAC_Em · Mar 04, 2020 at 04:16 PM ·
movementarraygrid based game2d array
Save a precalculated grid path into a jagged 2d array ready to be loaded when need
I have a 2D grid based movement system that uses flow fields to pass information at every node to an agent (if the agent is on the node) about which way it should travel in order to reach a target. The system updates and recalculates pathing when the agent moves onto a new node.
What i want to do now is be able to save every potential pathing outcome when the target is on any node in the grid. I have tried creating a 2D jagged array to loop through each point of the array and add my grid array values there.
public void precalculate()
{
outerTable = new Node[gridSizeX, gridSizeY][,];
for (int x = 0; x < gridSizeX; x++)
{
for (int y = 0; y < gridSizeY; y++)
{
//create grid is what i use to instantiate the grid with placeholder values
outerTable[x, y] = CreateGrid();
//I then get the world point of the target and pass it to calculateDistance which calculates the pathing
Vector3 worldPoint;
worldPoint.x = x;
worldPoint.y = y;
worldPoint.z = 0;
Node targetNode = gridAccessor.NodeFromWorldPoint(worldPoint);
gridAccessor.CalculateDistance(targetNode);
}
}
}
However this doesnt seem to be working, and i am unsure what i should do to fix this Any suggestions? Thanks
Comment