- What do you want to achieve? Keep it simple and clear!
I want to make a infinite voxel generation like minecraft
-
What is the issue? Include screenshots / videos if possible!
i cant make it generate the terrain and also the chunks are glitchy and it doenst blend
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i looked in developer hub but i didnt find nothing
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
here’s my code:
local block = game.ServerStorage.Block
local blockSize = block.Size
local worldSize = 16
chunks = {}
chunksurroudings = {Vector3.new(0,0,0),Vector3.new(16,0,0),Vector3.new(0,0,16),Vector3.new(0,0,-16),Vector3.new(16,0,16),Vector3.new(-16,0,16),Vector3.new(16,0,-16),Vector3.new(-16,0,0),Vector3.new(-16,0,-16)}
workspace.Seed.Value = math.random()
chunkindex = 0
--these terms come from things like sine waves
function chunk(start)
local frequency = 1/16
local amplitude = 10
chunkindex = chunkindex + math.random()
local baseHeight = 1+ amplitude/2
chunkmodel = Instance.new('Model',workspace.Chunks)
chunkmodel.Name = 'chunk:' .. start.X .. '/' .. start.Z
table.insert(chunks,chunkmodel)
for x = 1, worldSize do
for z = 1, worldSize do
local height = baseHeight + math.noise(
x * frequency,
workspace.Seed.Value + chunkindex,
z * frequency
) * amplitude
for y = 1, math.floor(height) do
local b = block:Clone()
b.Position = Vector3.new(start.X + x, y, start.Z + z) * blockSize
b.Parent = chunkmodel
end
end
end
end
while true do
wait(0.1)
for i,v in pairs(game.Players:GetChildren()) do
local char = v.Character
if char ~= nil then
local humanoidrootpart = char:FindFirstChild('HumanoidRootPart')
if humanoidrootpart ~= nil then
print(tostring(humanoidrootpart.Position))
for i,pos in pairs(chunksurroudings) do
if workspace.Chunks:FindFirstChild('chunk:' .. pos.X .. '/' .. pos.Z) == nil then
chunk(humanoidrootpart.Position + pos)
end
end
end
end
end
end