Rules of it:Create randomly generated points, Take neighbouring cells in range of maping variable and create “line”
results
local maping = 2
Script
local size = 20
local bs = 1
local startPos = game.Workspace.StartPos.Position
local dist = 6
local maping = 2
local cells = {}
local NewGeneration = {}
local cell = Instance.new("Part")
cell.BrickColor = BrickColor.White()
cell.Anchored = true
cell.Size = Vector3.new(1,1,1)*bs
local chance = 5
function connect (a,b)
local dist = (a-b).Magnitude
local cframe = CFrame.new(a,b) * CFrame.new(0,0,-dist/2)
local line = Instance.new("Part")
line.Size = Vector3.new(1,1,dist)
line.CFrame = cframe
line.Anchored = true
line.TopSurface = Enum.SurfaceType.Smooth
line.Parent = game.Workspace.OBJ
end
for x = 1,size do
for y = 1,size do
for z = 1,size do
local ch = math.random(0,chance)
if ch == 1 then
local newCell = cell:Clone()
newCell.Position = startPos + (Vector3.new(x,y,z)*dist)
newCell.TopSurface = Enum.SurfaceType.Smooth
newCell.Parent = game.Workspace.OBJ
cells[x.."."..y.."."..z] = newCell
end
end
end
end
for i,myCell in pairs(cells) do
NewGeneration[i] = {}
local num = 0
for x = -maping,maping do
for y = -maping,maping do
for z = -maping,maping do
local div = string.split(i,".")
local ix,iy,iz = tonumber(div[1]), tonumber(div[2]), tonumber(div[3])
local name = x+ix.."."..y+iy.."."..z+iz
local cell = cells[name]
if cell and cell ~= myCell then
num += 1
NewGeneration[i][name] = false
end
end
end
end
if num == 0 then
myCell:Destroy()
end
end
for i,myCell in pairs(cells) do
local myData = NewGeneration[i]
if myData ~= nil then
for i2,isConnected in pairs(myData) do
local isConnected2 = NewGeneration[i2][i]
if isConnected2 == false and isConnected == false then
NewGeneration[i2][i] = true
NewGeneration[i][i2] = true
connect(cells[i].Position,cells[i2].Position)
end
end
end
end
btw table named NewGeneration has nothing to do with actual new generation.
I just named that like this for some reason.