-
What do you want to achieve? Keep it simple and clear!
Hey guys, I am trying to make a voxel game with procedurally generated terrain, I want the map to be really big though so I need to spawn a lot of parts. -
What is the issue? Include screenshots / videos if possible!
I am having a major issue with the fact that spawning in a lot of parts has drastic effects on the performance, here’s a video showing what happens: https://youtu.be/zCTt5wnAB3A
and here’s a video of how the terrain itself looks: https://youtu.be/R3fKmUjC0Z4 , so I need some way of optimizing the blocks. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried throttling the generation and changing the properties of the blocks (no shadows, set canTouch to false). I also tried switching to a system from this thread: Procedurally generated voxel world but that seemed rather slow and not quite what I was looking for
Here’s my generating script, since that’s probably useful
local Chunks = -1
local Tunnels = 5
local Seed = tick()
local ReplicatedStorage = game.ReplicatedStorage
function GenChunk (Boundx1, Boundy1, Boundz1, Boundx2, Boundy2, Boundz2)
local Model = Instance.new("Model")
Chunks += 1
Model.Name = tostring(Chunks)
Model.Parent = workspace.Map
for i=Boundx1, Boundx2, 4 do
for j=Boundy1, Boundy2, 4 do
for k=Boundz1, Boundz2, 4 do
local Part = ReplicatedStorage.Blocks.TestPart:Clone()
Part.Anchored = true
Part.Size = Vector3.new(4, 4, 4)
Part.Position = Vector3.new(i, j, k)
Part.Parent = Model
end
end
end
end
local Resolution = 4
function GenWorm(len, x, y, z)
Tunnels += 1
local sX = math.noise(Tunnels/Resolution+.1,Seed)
local sY = math.noise(Tunnels/Resolution+sX+.1,Seed)
local sZ = math.noise(Tunnels/Resolution+sY+.1,Seed)
local WormCF = CFrame.new(sX*500+x,sY*500+y,sZ*500+y)
print("Worm "..Tunnels.." spawning at "..WormCF.X..", "..WormCF.Y..", "..WormCF.Z)
local Dist = (math.noise(Tunnels/4+WormCF.p.magnitude,Seed)+.5)*2500
for i = 1,Dist do
local X,Y,Z = math.noise(WormCF.X/Resolution+.1,Seed),math.noise(WormCF.Y/Resolution+.1,Seed),math.noise(WormCF.Z/Resolution+.1,Seed)
WormCF = WormCF*CFrame.Angles(X*2,Y*2,Z*2)*CFrame.new(0,0,-Resolution)
local Touching = workspace:GetPartBoundsInBox(CFrame.new(WormCF.Position), Vector3.one*math.random(9,15), OverlapParams.new())
for i = 1, #Touching-1 do
Touching[i]:Remove()
end
end
end
local xc = 16
local yc = 16
local zc = 16
local rc = 16
wait(1)
while wait(.1) do
if math.random(1,100+math.floor(math.sqrt(rc))*10) == 50 and rc > 50 then
GenWorm(math.random(500,4000), (math.random(0,1)*2-1)*xc+8, (math.random(0,1)*2-1)*yc+8, (math.random(0,1)*2-1)*zc+8)
end
GenChunk(xc, yc, zc, xc+8, yc+8, zc+8)
GenChunk(-xc, yc, zc, -xc+8, yc+8, zc+8)
GenChunk(xc, -yc, zc, xc+8, -yc+8, zc+8)
GenChunk(-xc, -yc, zc, xc+8, -yc+8, zc+8)
GenChunk(xc, yc, -zc, xc+8, yc+8, -zc+8)
GenChunk(-xc, yc, -zc, -xc+8, yc+8, -zc+8)
GenChunk(xc, -yc, -zc, xc+8, -yc+8, -zc+8)
GenChunk(-xc, -yc, -zc, xc+8, -yc+8, -zc+8)
GenChunk(-zc, yc, xc, -zc+8, yc+8, xc+8)
GenChunk(zc, yc, xc, zc+8, yc+8, xc+8)
GenChunk(-zc, -yc, xc, -zc+8, -yc+8, xc+8)
GenChunk(zc, -yc, xc, zc+8, -yc+8, xc+8)
GenChunk(-zc, yc, -xc, -zc+8, yc+8, -xc+8)
GenChunk(zc, yc, -xc, zc+8, yc+8, -xc+8)
GenChunk(-zc, -yc, -xc, -zc+8, -yc+8, -xc+8)
GenChunk(zc, -yc, -xc, zc+8, -yc+8, -xc+8)
GenChunk(yc, zc, xc, yc+8, zc+8, xc+8)
GenChunk(-yc, zc, xc, -yc+8, zc+8, xc+8)
GenChunk(yc, -zc, xc, yc+8, -zc+8, xc+8)
GenChunk(-yc, -zc, xc, yc+8, -zc+8, xc+8)
GenChunk(yc, zc, -xc, yc+8, zc+8, -xc+8)
GenChunk(-yc, zc, -xc, -yc+8, zc+8, -xc+8)
GenChunk(yc, -zc, -xc, yc+8, -zc+8, -xc+8)
GenChunk(-yc, -zc, -xc, yc+8, -zc+8, -xc+8)
--GenChunk(xc, yc, -zc, xc+4, yc+4, -zc+4)
xc += 12
if(zc >= rc) then
rc += 12
end
if(yc >= rc) then
yc = 0
zc += 12
end
if(xc >= rc) then
xc = 0
yc += 12
end
print("xc : "..tostring(xc).."yc : "..tostring(yc).."zc : "..tostring(zc))
end