3D Grid Pathing


I have a 3d cube grid of platforms. Some have platforms connecting to their neighbour, some have ladders going up/down a level. The data is structured in a 3xarray (similar to a voxel chunk).

Would it be possible to create a 3D grid/array with each node specifying whether it has a ladder or a platform (in the connection array) and then use A* Pathfinding Project to find the shortest route?

If I can’t, could I make a 2d grid for each level, then create a connector going up/down for the ladders?

Ideally I’d like to run a"find path" function that would return the Vector3 grid/node positions listing the shortest route to a platform :slight_smile:

Any help would be greatly appreciated


PS: I have the pro version


Try the LayeredGridGraph. It works like the grid graph, but supports several layers of grids.
You can then, if you cannot get it to automatically detect the layer connections, add connections manually. Use for example the Menubar -> Edit -> Pathfinding -> Link Objects command when you have two gameobjects selected (positioned at the top and bottom of the ladder).


Thanks for the quick reply - sounds good! I remember seeing somewhere in the code that layered grid nodes have a limit of 4 connectors - is that correct? Some platforms will have 8, so that might be a problem :slight_smile:

Everything is being procedurally generated, does the following sound sensible?

  1. cycle through 3x nested array
  2. create grid for X and Z
  3. create new grid each Y
  4. I assume the layer grid class has an array of grids? If so, add each grid to array…
  5. cycle through each grid, create connections between layers for the stair platforms.
    (6) create connections between platform chunks…)

Unfortunately, I cant find any docs on how do this script-level… perhaps I’m being blind?



The LayeredGridGraph does not have a grid for each Y level, that would use huge amounts of memory. It only has nodes where there is actual ground.
You only need to create a single LayeredGridGraph.
The LayeredGridNodes have a limit of 4 on-grid connections. But you can add custom connections (every node has a .connections array, this uses more memory than the grid connections, but it doesn’t matter much for your game I think). You could either procedurally create GameObjects and attach a NodeLink script to link it (then you would have to Scan the graphs), or you could add connections manually using something like

Node node = AstarPath.active.GetNearest (a).node; Node node2 = AstarPath.active.GetNearest (b).node; node.AddConnection (node2, (node.position-node2.position).costMagnitude); node2.AddConnection (node, (node.position-node2.position).costMagnitude);

Awesome :slight_smile: Will the system play nice with nodes directly above or below other nodes? The platforms are uniformly spaced (6x6 each level)



I think so. Try it.

Hi Aron,

I’ve been beating my head against this all week and have made pretty much no progress. I know it’s a pain in the arse, but would it be possible for you to provide a code example? Let’s say for a chunk generated by something like.
for (int x = 0; x<10; x++){
for (int y = 0; y<10; y++){
for (int z = 0; z<10; z++){
Vector3 posOfNode = new Vector3 (x,y,z);


For each node/pos, I already have a generated list of which nodes are accessible from that point (currently as Vector3’s but I can change this to whatever).

For some nodes it’s only one or two adjacent on the X and Z, for some it’s 6 adjacent nodes on the X and Z and 2 above and below (Y).

Because each chunk is different I’m going to need to generate everything at script level

Any help would be really appreciated :slight_smile:



Hm, ok. If it needs to be that low level, I think it might be easier to just create a graph from scratch. There is a tutorial in the docs: http://arongranberg.com/astar/docs/writing-graph-generators.php

Hi all, I’m trying to do the same thing that the OP has posted. I overrode the LayerGridGraph class with my own Scan() functionality and manually (as a test) add connections to some nodes myself. Right now I have the following test scene:

I have a connection between the SW corner of the ground to the SW corner of the balcony.
I’m spawning the seeker at the NW corner of the ground and I set its target to the NE corner of the balcony.

When I run the scene, the seeker appears to find the right path (green line) but he doesn’t move properly: he just fumbles comically under the balcony near the ladder:


This is how I’m adding the connection:

public override void Scan()
onPreScan ();
base.Scan ();
OnPostScan ();

// from well known scene/node layout
int xBottom = 0;
int zBottom = 0;
int xTop = 1;
int zTop = 0;
int index1 = ( xBottom + ( width * zBottom ) );
int index2 = ( xTop + ( width * zTop ) + ( width * depth * 1 ) );
nodes[index1].AddConnection (nodes[index2],3000);
nodes[index2].AddConnection (nodes[index1],3000);


Is this the proper way to add connections to simulate ladders? Does anyone why why my seeker won’t follow the path properly?