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

Terrain Generation CFraming Issue?

Asked by 6 years ago
Edited 6 years ago

Hello there, I have been having an issue trying to figure out how to actually create some sort of triangular terrain through terrain generation. I am currently using wedges as the example brick to generate the rows.

Here is the code:

function MakeTriangularTerrain(dummyPart, row, column, parent)
    local triangleStartPos = dummyPart.CFrame;
    local currentRow = 1;
    local currentCol = 1;

    for Row = currentRow, row do
        wait();

        local triangleWedge = dummyPart:Clone();
        triangleWedge.Parent = parent;
        triangleWedge.BrickColor = BrickColor.new("Really red");
        triangleWedge.CanCollide = false;

        local rowTriangle = triangleWedge;
        local rowSize = rowTriangle.Size;
        local currentCFrame = triangleWedge.CFrame;

        --rowTriangle.CFrame = currentCFrame;
        rowTriangle.Orientation = Vector3.new(0, 90, -90);

        if Row%2 == 0 then
            rowTriangle.CFrame = currentCFrame * CFrame.new(0, (rowSize.Y * Row)/2, 0);
            rowTriangle.BrickColor = BrickColor.new("Bright green");
            rowTriangle.Orientation = Vector3.new(0, -90, -90);
        end
        currentCFrame = rowTriangle.CFrame;

    end
end

MakeTriangularTerrain(workspace.TestTriangle, 3, 1, workspace);

Basically, my issue is after spawning the green wedge part it actually does spawn the rotated red one but doesn't move it to the next position, I am currently not seeing how to reset the position and set the new position so it actually does as shown:

Any help to enlighten this a bit more is apreciated!

1 answer

Log in to vote
1
Answered by
iloveu6 20
6 years ago

I believe what you did is forget to add an actual function for the red triangles to be positioned. In studio I tested this script out and came up with this (it has manual mathematics, I didn't generate the positions or anything, so you might want to change that):

function MakeTriangularTerrain(dummyPart, row, column, parent)
local triangleStartPos = dummyPart.CFrame
local currentRow = 1
local currentCol = 1

for Row = currentRow, row do
wait()
local triangleWedge = dummyPart:Clone()
    triangleWedge.Parent = parent
    triangleWedge.BrickColor = BrickColor.new("Really red")
    triangleWedge.CanCollide = false

local rowTriangle = triangleWedge
local rowSize = rowTriangle.Size
local currentCFrame = triangleWedge.CFrame
--rowTriangle.CFrame = currentCFrame;
rowTriangle.Orientation = Vector3.new(0, 90, -90)

if Row%2 == 0 then
    rowTriangle.CFrame = currentCFrame * CFrame.new(0, (rowSize.Y * Row)/2, 0)
    rowTriangle.BrickColor = BrickColor.new("Bright green")
    rowTriangle.Orientation = Vector3.new(0, -90, -90)
else
    triangleWedge.CFrame = currentCFrame * CFrame.new(0, ((rowSize.Y * Row)/2)-1.4, 0)
    triangleWedge.Orientation = Vector3.new(0, 90, -90)
end
    currentCFrame = rowTriangle.CFrame
    end
end
MakeTriangularTerrain(workspace.TestTriangle, 30, 1, workspace)

The part where you put "Row%2 == 0" means that it divides the row by 2 and if the remainder (which will only be either 1 or 0 because it's even/odd integers) only moves when it reaches 0, which is every even number (For example: 1 is the placekeeper but when it gets to 2 it's positioned, then 3 it skips because it's odd, then it goes to 4 and so on...)

Hope this helps! (My first post so I sure hope so lol)

GIF of what happens

0
Actually not my first post :O, oh well! iloveu6 20 — 6y
0
In the CFraming of triangleWedge on the else scope, why did you actually put that "-1.4" ? iDarkGames 483 — 6y
0
Just to get the positioning right. It's manual mathematics, which I DO NOT recommend you use while using CFrame, I would instead try to find some type of algorithm but this worked for me so iloveu6 20 — 6y
0
Okay, thank you for enligthening me. iDarkGames 483 — 6y
0
Thank you for giving me my first solved question! iloveu6 20 — 6y
Ad

Answer this question