Skip to content

Instantly share code, notes, and snippets.

@GeorgiyRyaposov
Created November 18, 2020 06:57
Show Gist options
  • Save GeorgiyRyaposov/bb7cc5e59f926dfef91ff37b06a97e7f to your computer and use it in GitHub Desktop.
Save GeorgiyRyaposov/bb7cc5e59f926dfef91ff37b06a97e7f to your computer and use it in GitHub Desktop.
Convert unity hex coords to cube hex coords
private Vector3Int UnityCellToCube(Vector3Int cell)
{
var yCell = cell.x;
var xCell = cell.y;
var x = yCell - (xCell - (xCell & 1)) / 2;
var z = xCell;
var y = -x - z;
return new Vector3Int(x, y, z);
}
private Vector3Int CubeToUnityCell(Vector3Int cube)
{
var x = cube.x;
var z = cube.z;
var col = x + (z - (z & 1)) / 2;
var row = z;
return new Vector3Int(col, row, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment