How to get Hexagonal Grid position from WorldPosition in Unity

30 Views Asked by At

I am currently building a hexagonal grid system in unity, with hexagons whose dimension is a little different than regular one. It's pointy-top, but its height and width is all 1, instead of 1 and sqrt(3), to match unity tilemap size and I prefer the way it looks to regular one. And that's where my problem starts..

I want to write a method in which I can translate Vector3 world position to Hex Grid position (Cube Coordinate), but since it's dimension is tilted, regular methods don't work.

How can I get the Hex Grid position with world Position? any help please?

I tried pretty much all the algorithms in redblobgames.com but none of it seems working.

1

There are 1 best solutions below

0
Andriy Marshalek On

There is a nice Unity tutorial series about the hexagon maps: https://catlikecoding.com/unity/tutorials/hex-map/part-1/

All of the math and stuff like that is nicely explained.