Positioning hex tiles

Currently, I’ve created this method of generating hexes for a map I’m making.
However, I don’t know how to properly position the hexagons into a proper hex map to get a result like this.

What exactly is the math behind it?

I found this article, it goes in a lot more depth than I can.

1 Like

I’ve already seen that post, not particularly helpful when again, I don’t understand the method behind it.

How about this?

How about what? This video is only a showcase and doesn’t explain how to position hex tiles.

I apologise.

These are all threads relating to hexgrids/hexmaps etc.

Please stop only posting links, I have read every attempted solution. None of which explains the math behind positioning hex tiles.

I’m not a programmer and this probably won’t help much if at all, but I found this article about Hexagonal tiling.

I’m working on rewriting a strategy game involving hexagonal tiles, the article from Red Blob Games and another from CatLikeCoding helped me achieve this.

The horizontal distance (as mentioned in the Red Blob Games article), is 1/2 of the tile’s width. The vertical distance, is 3/4 of the tile’s height.

To generate a small, rectangular area of hexagonal tiles, you can do the following:

local tile = workspace.Tile

--! change these values to match the X and Z size of your tile mesh.
local tileWidth = 3.464
local tileHeight = 4

local gridWidth = 24
local gridHeight = 24


function AddTile( xPosition: number, zPosition: number )
	xPosition *= tileWidth

	--? we offset the second row slightly by 1/2 the tile's width.
	if zPosition % 2 == 0 then
		xPosition += tileWidth * 0.5
	end
	zPosition *= tileHeight * 0.75

	local tile = tile:Clone()
	tile.CFrame = CFrame.new(Vector3.new(xPosition, 0, zPosition))
	tile.Parent = workspace
end


for zPos = 1, gridWidth do
	for xPos = 1, gridHeight do
		AddTile(xPos, zPos)
	end
end

At the end of it, you should have something like this:

I hope this helped!

3 Likes

That post explains the method and the math quite clearly. I could give you a hand if you’ll explain what you’re struggling with though.