Tag Grid Nodes by altitude

Hi, I want to limit different AI to certain altitudes. The first solution come into my mind with A* is to mark nodes with different tags according to their world space y position upon their generation.
Is it possible to be achieved by creating a new grid graph generator and mark the node’s tags when generating?
Can I use the ProceduralGridMover script in the procedural example to achieve this,too?
If so, where should I start?

Hi

If you also want to use the ProceduralGridMover then you will have to subclass the grid graph and then add your custom grid graph in the inspector.

You can subclass it like this:

using pathfinding;

public class MyGridGraph : GridGraph {
	public override void RecalculateCell (int x, int z, bool resetPenalties = true, bool resetTags = true) {
		base.RecalculateCell(x, z, resetPenalties, resetTags);
		var node = nodes[z*width + x];
                // Modify the node here somehow
                if (node.y > 5) node.Tag = 3;
               
               // Need to set this if you modify the walkability in any way, otherwise erosion will not work
               node.WalkableErosion = node.Walkable;
	}
}
// In an editor script
using pathfinding;

[CustomGraphEditor(typeof(MyGridGraph), "My Grid Graph")]
public class MyGridGraphEditor : GridGraphEditor {
}

Thanks! Will try this!

1 Like