Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

[Hex Terrain]Why is it producing a little gap?

Asked by 6 years ago
Edited 6 years ago

I am not sure why is it producing that little gap on this hexagon generator script.

Provided picture:

Provided model:

function MakeHexTerrain(dummy, rows, columns, parent)
    local currentRow = 1;
    local currentColumn = 1;
    dummy.Parent = parent;
    local StartPos = dummy.CFrame;
    for Row = currentRow, rows do
        local row = dummy:Clone();
        row.BrickColor ='Really red');
        row.Parent = parent;
        local rowPosition = row.CFrame;
        local rowSize = row.Size;

        row.CFrame = rowPosition *, 0, rowSize.Z * Row);
        if Row%2 == 0 then
           row.CFrame = row.CFrame *,0,0) 
        rowPosition = row.CFrame;

        for Column = currentColumn, columns do
            local column = dummy:Clone();
            column.BrickColor ='Forest green');
            column.Parent = parent;
            local columnPosition = column.CFrame;
            local columnSize = column.Size;
            column.CFrame = rowPosition *, 0, 0);
            rowPosition = column.CFrame;

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.

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
Oh, I'm sorry, let me update. iDarkGames 483 — 6y
It's difficult to figure a solution without the specific object.. could you link to a model on roblox or something? Goulstem 8144 — 6y
There you go, and sorry once again. iDarkGames 483 — 6y
View all comments (2 more)
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
Okay, thanks Goulstem! iDarkGames 483 — 6y

1 answer

Log in to vote
Answered by
blowup999 659 Moderation Voter
6 years ago
Edited 6 years ago
row.CFrame = rowPosition *, 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

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

Answer this question