Dear
Im working on a minecraft-like game. The terrain is for now represented as:
Tile[,] mapIndex = new Tile[widht, height, depth];
A tile contains its position, materialId and also its walkability.
After some investigations i was able to rewrite the SampleCell() function like this
LinkedLevelNode SampleCell(int x, int z)
{
if (World.instance == null)
return new LinkedLevelNode();
LinkedLevelNode[] nodes = new LinkedLevelNode[World.instance.mapHeight];
int nodeCount = 0;
for (int y = 0; y < World.instance.mapHeight; y++)
{
if (World.instance.mapIndex[x, z, y].walkable)
{
nodes[nodeCount] = new LinkedLevelNode();
nodes[nodeCount].position = new Vector3(x, y + 1f, z); //Assets.UltimateIsometricToolkit.Scripts.Utils.Isometric.IsoToUnitySpace(new Vector3(x, y + 1f, z));
nodes[nodeCount].height = 0.5f;
nodes[nodeCount].walkable = true;
if (nodeCount > 0)
{
nodes[nodeCount - 1].next = nodes[nodeCount];
}
nodeCount++;
}
}
return nodes[0];
}
And as a result, it finally works! I can move my AI from every tile to every tile. But the AI should only be able to go up and down stairs (see picture).
I think that means I need to rewrite the CalculateConnections () function so it will just connect tiles at the same height and then I’ll need a logic for connecting nodes to stairs later at RUNTIME up and down.
I’ve really tried to do it myself, but I can not figure out how connections work. All I see is “node.SetConnectionValue (dir, conn);”. I thought there was something like node.SetConnection (ie Dir.UP, dir.Left …), but it looks a lot more complicated.
In addition, I ask how it is possible to have only four connections? What if a tile needs to be connected up, down, forward, back, left, and right?
Picture shows game-world, graph and a stair:
I really hope you understand what my goal is. I am very grateful for any help, tips and information.
Thank you very much for your time!
Greetings