Scripting Helpers is winding down operations and is now read-only. More info→

Log in to vote

2
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.

0

Could you provide a screenshot? I don't have your hexagon object so it's just doing it with parts. Pretty sure the problem is the condition on line 14, though.. Goulstem 8144 — 6y

0

Oh, I'm sorry, let me update. iDarkGames 483 — 6y

0

It's difficult to figure a solution without the specific object.. could you link to a model on roblox or something? Goulstem 8144 — 6y

0

There you go, and sorry once again. iDarkGames 483 — 6y

View all comments (2 more)

0

I have to go for now but this question intrigues me and i'll be sure to answer later if it hasn't been already. Goulstem 8144 — 6y

0

Okay, thanks Goulstem! iDarkGames 483 — 6y

Log in to vote

1
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

https://gyazo.com/a9c1a6bd9a36365ec28e12b1033247ed

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

0

I didn't explain it super well but if's hard to understand unless you've taken a trig class blowup999 659 — 6y