Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Terrain Generation CFraming Issue?

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

✓ Accepted answer

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

5 comments

0

Actually not my first post :O, oh well!

0

In the CFraming of triangleWedge on the else scope, why did you actually put that "-1.4" ?

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

0

Okay, thank you for enligthening me.

0

Thank you for giving me my first solved question!

This discussion is preserved as it was. New answers, comments, and votes are closed.