#Hexagonal Tilemap Coordinates
1 messages · Page 1 of 1 (latest)
I've already looked at this great documentation, but I can't seem to apply it
What exactly is the problem here? Sorry I don’t quite understand what you’re asking
As you can see on my first screenshot, instead of detecting all the cells adjacent to my central cell, it returns me wrong coordinates. Many tutorials use the size of the hexagons to make the coordinate system, but I don't know how to integrate it using hexagonal tilemaps.
I did something like this custom recently and i only used vector2int for positions
x being odd/even is used to correct the neighbours retrieved
Here is a snippet of this. The y offset column is different to the unity grid component
int yOffset = (pos.x + 1) % 2;
Span<Vector2Int> neighbourPositions = stackalloc Vector2Int[6]
{
new (pos.x, pos.y + 1),
new(pos.x - 1, pos.y + 1 - yOffset), new(pos.x + 1, pos.y + 1 - yOffset),
new(pos.x - 1, pos.y + 0 - yOffset), new(pos.x + 1, pos.y + 0 - yOffset),
new(pos.x, pos.y - 1)
};