I’m trying to do move from Cartesian to a slanted approach like described but I having issues. Hex grids are confusing me. The Cartesian coordinates are easy to layout for me but hard to expand on but having one axis slanted diagonal is easy to expand on but I’m having a hard time laying it out.
Thanks for your time.
Here is my grid working laid out using the Cartesian coordinates.
public void Intialize()
{
pathNodes = new PathNode[width, depth];
//Create our Grid
for (int x = 0; x < width; x++)
{
for (int z = 0; z < depth; z++)
{
PathNode pathNode = new PathNode();
pathNode.gridNodeIndex = new Vector2(x, z);
pathNode.isWalkable = true;
//POSITION OUR NODE
float offset = 0;
if (z % 2 != 0)
offset = nodeSize * 0.5f;
pathNode.position = new Vector3(offset + x * nodeSize, 0, z * nodeSize * 0.75f);
pathNodes[x, z] = pathNode;
}
}
}
Edit : Never mind, read post below.
Ok I got it to work. I’m still using Cartesian coordinates and I just worked on the expansion. All I had to do was take a break and the answer hit me. I just needed to check if the tile is offseted during expansion(Stupid Past me). Anyway here is code.
Creating our grid node positions
public void Intialize()
{
pathNodes = new PathNode[width, depth];
//Create our Grid
for (int x = 0; x < width; x++)
{
for (int z = 0; z < depth; z++)
{
PathNode pathNode = new PathNode();
pathNode.gridNodeIndex = new Vector2(x, z);
pathNode.isWalkable = true;
//POSITION OUR NODE
float offset = 0;
if (x % 2 != 0)
offset = nodeSize * 0.5f;
pathNode.position = new Vector3(offset + y * nodeSize, 0, x * nodeSize);
pathNodes[x, z] = pathNode;
}
}
}
Simplifies, and converts the hexadecimal matrix in a two dimensional array.
Then you can use an ordinary algorithm pathfinding.
Colums = Width and Files = Height * 2 - 1.
In even-numbered columns, the first position is repeated twice, and the latter once.
In odd-numbered columns, the first position is not repeated, and the last repeats.
Hmm, this is a cool format. I’ve never seen this before. Nice and simple! Well, I’ve already got three formats used, I don’t think I need another. Anyways, good work from a fellow hexagon nerd.