Time to make this:40 minutes
Complexity:Medium
Please rate originality of this project ,script itself and give your personal opinion in total
Script i want to show you (I would appreciate that if you read my script
and scroll down to see results of this script)
local size = 10 --how many time it will be runned trough single for loop
local bs = 1 --basic size. it's basically size of "cell"
local startPos = Vector3.new(0,0,0)
local dist = 4--distance between cells
local maping = 1--how far i'll be looking for neighbours
local cells = {}
local NewGeneration = {}
local chance = 4 --don't be confused but if chance var is smaller then cell's chance for appearing is higher. But i can change that in future if you want to
isGenerating = true
---
local cell = Instance.new("Part") --bassic cell to not waste script later you can remove that if you want but you need to define cell later or modifiy script
cell.BrickColor = BrickColor.White()
cell.Anchored = true
cell.Size = Vector3.new(1,1,1)*bs
---
local function connect (a,b)
local dist2 = (a-b).Magnitude
local cframe = CFrame.new(a,b) * CFrame.new(0,0,-dist2/2)
local line = Instance.new("Part")
line.Size = Vector3.new(1,1,dist2)
line.CFrame = cframe
line.CastShadow = false
line.Anchored = true
line.TopSurface = Enum.SurfaceType.Smooth
line.BottomSurface = Enum.SurfaceType.Smooth
line.Color = Color3.new(0,0,(dist2/dist)/2)
line.Parent = game.Workspace
end
for x = -size/2,size/2 do
for y = -size/2,size/2 do
for z = -size/2,size/2 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
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
results
Current sethings:
size = 20
maping = 2
dist = 12
bs = 1
chance = 4
