2d Grid


(Greg) #1

I’m building a 2D game where a hexagonal grid lives in the XY plane.

Since MapNav2 generates the grid in the XZ plane by default (and there doesn’t seem to be an option to choose a different plane to use), I made the following changes to the source code:

MapNavHexa.cs, line 140:

grid[idx].localPosition = new Vector3(px, nodeHeightStep * grid[idx].h, py);

Replace with:

grid[idx].localPosition = new Vector3(px, py, nodeHeightStep * grid[idx].h);
grid[idx].parent.rotation = Quaternion.Euler(-90, 0, 0);

This is what the end result looks like (looks and works as expected):

However, this is what it looks like in the scene view:

I was wondering what the proper way to render a grid in the XY plane is, and whether the approach I’ve chosen is going to have some unexpected consequences. Also I don’t really understand whether my tiles are actually rotated as the debugger shows or is it just that the debugger draws them in the XZ plane by default.

Thanks!


(Leslie Young) #2

It looks like your changes are placing the nodes in the correct position.
Have a look at MapNavHexa.OnDrawGizmos() for the code drawing the debug view. See if changing the code on line 1150 helps… p2 = new Vector3(xi, p2.y, zi);


(Greg) #3

Thanks Leslie!

Yes, changing that line to swap the last two arguments helps. I also had to modify the line where the value is assigned to the zi variable to read from grid[idx].position.y instead of z.

Love MapNav2 so far! Great work.