Help generating triangles between nodes - SOLVED

Help generating triangles between nodes - SOLVED

I’m trying to figure out how to generate triangles between each generated node, but the problem is that I don’t even know where to start from. I’ve also looked up some solutions to solve my problem, but most talk about the arithmetic on triangle terrain.

What I am trying to do is, to generate triangles that position themselves to fit the area size of a node. After the triangles are placed, I want them to be formed all together to reduce lag. Is there anything you can do to solve this problem?

Here is the code from the script (Not localscript.)

wait(6)
print("script started...")
-- Raycasting Properties
local RaycastHeightStart = 100 -- Start of the raycasting system.
local RaycastOffset = Vector3.new(0,0,0) -- Offset the position that will affect the area.
local RaycastSize = Vector3.new(1000,0,1000) -- The area that will be affected.
local GenerationSpeed = 20 -- How fast the nodes will generate.
local RaycastIncrement = 8 -- How many Nodes that will be spreaded apart. (The detail of the Nodes)

-- Node Properties
local NodeSize = 3 -- How big the nodes are.
local NodeColor = Color3.new(0, 0, 0)
local NodeMaterial = Enum.Material.SmoothPlastic
local NodePositionOffset = Vector3.new(0,0,0) -- The offset position of the nodes after placement.

-- Main Parts
local Nodes = Instance.new("Folder") -- Make Node Folder.
Nodes.Parent = game.Workspace
Nodes.Name = "NodeFolder"
local Triangles = Instance.new("Folder") -- Makde Triangle Folder.
Triangles.Parent = game.Workspace
Triangles.Name = "TriangleFolder"

local Params = RaycastParams.new()
for x = 0,RaycastSize.X,RaycastIncrement do -- Create waves of nodes.
	for z = 0,RaycastSize.Z,RaycastIncrement do
		local raycastResult = workspace:Raycast(Vector3.new(x,10000,z),Vector3.new(0,-1000000,0),Params) -- Detect if terrain is detected.

		if raycastResult then -- If terrain is detected, create nodes.
			local Position = raycastResult.Position
			local Node = Instance.new("Part")
			Node.Name = "Node"
			Node.Position = Position + NodePositionOffset
			Node.Material = NodeMaterial
			Node.Color = NodeColor
			Node.Size = Vector3.new(NodeSize,NodeSize,NodeSize)
			Node.Anchored = true
			Node.Transparency = 0
			Node.Parent = Nodes
		end
	end
	if x % GenerationSpeed == 0 then wait() end -- The generation speed, reduces lag spikes.
end

Thank you.

I knew I’d seen this done before, so I went digging. What I found is from this post:

The example does exactly what you want. You may have to edit the provided example to suit your needs though.

1 Like