Hello fellow developer!
I’'ve written a script for a project i’ve been working on. The goal is to acheive artificial randomly generated terrain each time you enter the game.
So far, i’ve made good progress with a system that creates nodes that then get connected.
(Sorry for the lag, studio issue)
I have yet to do the hard part. I need to connect these nodes using triangles. I’ve attempting doing a similar system to my connections, but that failed. I cant seem to find any devforum articles that are similar to mine.
Heres a copy of the code:
nodezero = workspace.Nodes.Node0
local Nodenum = 0
lastnode = nodezero
while Nodenum < 677 do -- Creates and positions nodes
Nodenum = Nodenum + 1
newnode = nodezero:Clone()
newnode.Parent = workspace.Nodes
newnode.Name = "Node" .. tostring(Nodenum)
x = lastnode.Position.X + 20
y = math.random(0, script:GetAttribute("Intensity"))
z = lastnode.Position.Z
if math.floor(Nodenum / 26) == Nodenum / 26 then
x = -244
z = lastnode.Position.Z + 20
end
newnode.Position = Vector3.new(x,y,z)
lastnode = newnode
end
Nodenum = 0
while Nodenum < 676 do -- places and positions X connections
local a = workspace.Nodes['Node' .. tostring(Nodenum)].Position
local b = workspace.Nodes['Node' .. tostring(Nodenum + 1)].Position
local distance = (a-b).magnitude
local midPosition = (a+b)/2
local UP = Vector3.new(0,1,0)
local thickness = 1
if distance < 150 then
local part = Instance.new("Part")
part.Anchored = true
part.Color = Color3.new(0, 1, 0)
part.Size = Vector3.new(thickness, thickness, distance)
part.CFrame = CFrame.lookAt(midPosition, b, UP)
part.Parent = workspace
end
Nodenum = Nodenum + 1
end
Nodenum = 0
while Nodenum < 650 do -- places and positions Z connections.
local a = workspace.Nodes['Node' .. tostring(Nodenum)].Position
local b = workspace.Nodes['Node' .. tostring(Nodenum + 26)].Position
local distance = (a-b).magnitude
local midPosition = (a+b)/2
local UP = Vector3.new(0,1,0)
local thickness = 1
if distance < 150 then
local part = Instance.new("Part")
part.Anchored = true
part.Color = Color3.new(0, 1, 0)
part.Size = Vector3.new(thickness, thickness, distance)
part.CFrame = CFrame.lookAt(midPosition, b, UP)
part.Parent = workspace
end
Nodenum = Nodenum + 1
end
I hope this problem can be sorted out and im willing to provide more information in the future.