How to make the correct rotation of a hexagon tile on spheric grid ?
Hi,
I have a rotation problem in my hexasphere project : I can't correctly rotate my tiles to generate a grid. I have to use "physical" tiles like blocks in Minecraft.
To generate hexagon tiles, i use a "sphere skeleton" and use vertices to fixe the tiles on them.
Can you help me to find a generic solution ? I mean I need a solution that I can use for the tiles of all layers/depths and correctly rotate the props on them too :)
Thanks for your help.
private void GenerateTiles()
{
Vector3[] vertices = this.GetComponent<MeshFilter>().sharedMesh.vertices;
foreach(Vector3 vertice in vertices)
{
GameObject child = Instantiate(
this.GetComponent<Planet>().tiles[0], // Tmp tile
this.tilesContainer.transform
);
Tile tile = child.GetComponent<Tile>();
tile.body.transform.position = vertice;
tile.body.transform.localScale = new Vector3(ratio, ratio, ratio);
tile.body.transform.rotation =
Quaternion.LookRotation(-vertice.normalized) * Quaternion.Euler(0f, 90f, 90f);
}
}
Generated tiles :
One tile :
Your answer
Follow this Question
Related Questions
Why won't my random tile generator not working?? 0 Answers
Obtain Sprite Data from Tile in a Grid Using Tile Coordinates 1 Answer
Tilemap grid for hexagon tiles 0 Answers
Solution for a Tiles Instantiated Object not appearing on Tile Palette? 0 Answers
Help with tile palette(Genuine Struggle) 0 Answers