Created
November 18, 2020 06:57
-
-
Save GeorgiyRyaposov/bb7cc5e59f926dfef91ff37b06a97e7f to your computer and use it in GitHub Desktop.
Convert unity hex coords to cube hex coords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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