I am not sure why is it producing that little gap on this hexagon generator script.
Provided picture: https://gyazo.com/674e2a451561179a638470f7c16b2145
Provided model: https://www.roblox.com/my/item.aspx?id=932301764
function MakeHexTerrain(dummy, rows, columns, parent) local currentRow = 1; local currentColumn = 1; dummy.Parent = parent; local StartPos = dummy.CFrame; for Row = currentRow, rows do wait(); local row = dummy:Clone(); row.BrickColor = BrickColor.new('Really red'); row.Parent = parent; local rowPosition = row.CFrame; local rowSize = row.Size; row.CFrame = rowPosition * CFrame.new(0, 0, rowSize.Z * Row); if Row%2 == 0 then row.CFrame = row.CFrame * CFrame.new(row.Size.X/2,0,0) end; rowPosition = row.CFrame; for Column = currentColumn, columns do wait(); local column = dummy:Clone(); column.BrickColor = BrickColor.new('Forest green'); column.Parent = parent; local columnPosition = column.CFrame; local columnSize = column.Size; column.CFrame = rowPosition * CFrame.new(columnSize.X, 0, 0); rowPosition = column.CFrame; end; end; end; MakeHexTerrain(workspace.Hexagon, 10, 10, workspace);
I know the generator is innacurate, but I am unsure on why is it producing a gap like that.
row.CFrame = rowPosition * CFrame.new(0, 0, (1 - math.cos(math.pi/3)/2) * rowSize.Z * Row);
Changing that line to that will fix it
If you imagine a box around the Hexagon that's it's size. When you move it down by it's size, you're making it so the tip of one end hits the tip of the other, but that's not what you're trying to do. So you have to remove the z distance from the tip of one to the side of the other, which is what the equation does using a little trig
So if you were to take that hexagon and move it to the right so the tips aligned then move it halfway up there would be a gap between the top right vertex of the original and the very left vertex of the new hexagon. In order to fix that gap I subtracted the cosine of 60 degrees and divided by two