Hexagon Grid

Hello,

I’ve built a hexagon grid using some coordinates that I input into the game. However, the algorithm I’m using to place these doesn’t appear to be how I want it.

This is how it places them currently:

87138-actual.png

I would like the X axis to be horizontal, however it currently goes diagonal lower-right. This is how I would like it to be:

87140-a-wanting.png

As you can see, the X axis is horizontal, with every odd on a negative placement (1,0… 3,0… 5,0… etc).

This is the algorithm I’m using:

public static Vector3 HexCoordinateToWorld(Vector2 _coordinates){

		float _sqrt32 = (float)Mathf.Sqrt(3)/2;
		float _size = 40.24f;

		float _x = _size * (float)_coordinates.x * 1.5f;
		float _y = _size * (2 * _coordinates.y - _coordinates.x) * _sqrt32;

		return new Vector3(_x, 0, _y);
	}

Build it like it was a rectangular grid and then offset every odd row.

The Y calculation would be looking something like this:

if (_coordinates.x % 2 == 0)
{
   //don't offset Y position
}
else
{
   //offset Y position
}