- Home /
Unity 2020 WorldToCell for Hexagonal Tilemap
Hello everyone,
I'm using unity 2020 and working on a 2D project. I would like to know the Tile coordinate where my mouse is over.
To do so, I use:
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
To get the real world mouse Position. Then,
grid.WorldToCell(mouseWorldPos)
or
tilemap.WorldToCell(mouseWorldPos)
To Get the cell coordinate.
But this doesn't work with hexagonal Tilemap.
I tried this solution : https://answers.unity.com/questions/1493887/how-to-convert-world-position-to-hex-grid-coordina.html but the results are incorrect too.
For information, I set my tiles size as following X=2.598 Y=3.
Can Someone help me please ?
Answer by fb69 · Nov 13, 2020 at 11:41 AM
My Bad !
The grid.WorldToCell(mouseWorldPos)
method works well. Even for orthogonnal Grids.
The problem was that I changed the Grid type and the tilemap keeps the anchors at 0.5. For an hexagonal tilemap, anchors are at 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220613015641im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Change hex tilemap to use axial coordinates? 0 Answers
Delete Tiles Outside of Tile Map 0 Answers