#Help adding procedural generation where the player generates chunks
1 messages · Page 1 of 1 (latest)
have you installed infinite terrain ?
yeah
when you press settup
you will find 2 scripts
one script keeps track of what chunks to load and unload
and the other is the actor that loads and unloads the terrain
so where do I put the generation
that does not make sense to me
I meant what script do I put it in
you dont put no script in it
you read the code and work out how it works
then try to make your own version of it
how do I put my generation into it though
i dont know what your generation is
you can delete that and make a new one
where did you find that script from?
but its 3d noise does the infinite terrain support that?
ok because its using depreciated things
its a little out of date
if i give you a task can you try and do it
it does not mater what infinite terrain supports
to write 64x64x64 voxels of sand
once you done that ill tell you the next step
ok
ok I finished the cube thing
-- Create a function to generate a single cube
local function createCube(x, y, z)
local cube = Instance.new("Part")
cube.Size = Vector3.new(3, 3, 3) -- Set cube size to 3x3x3
cube.Position = Vector3.new(x, y, z) -- Set cube position directly
cube.Anchored = true
cube.Parent = workspace
return cube
end
-- Create a function to generate the big cube
local function createBigCube()
for x = 0, 63, 3 do
for y = 0, 65, 3 do
for z = 0, 63, 3 do
local cube = createCube(x, y, z)
cube.Parent = workspace
workspace.Terrain:FillBlock(cube.CFrame, Vector3.new(3,3,3), Enum.Material.Sand)
cube:Destroy()
end
end
end
end
-- Call the createBigCube function to generate the big cube
createBigCube()
no
what
thats not what i asked
what did you ask its 64x64x64 voxels of sand right?
no
wdym
wait so you want me to make the terrain but without the part?
i want you to use WriteVoxels and write 64 x 64 x 64 of sand
what does writing mean does it mean saving it to somewhere?
wait what Im confused
oh thats what you mean
i think I got something working:
xArrayMax=64
yArrayMax=64
zArrayMax=64
xVoxelMax=xArrayMax4
yVoxelMax=yArrayMax4
zVoxelMax=zArrayMax*4
Material = Enum.Material.Sand
AreaMaterial={}
AreaOccupancy={}
for x=1,xArrayMax,1 do
AreaMaterial[x]={}
AreaOccupancy[x]={}
for y=1,yArrayMax,1 do
AreaMaterial[x][y]={}
AreaOccupancy[x][y]={}
for z=1,zArrayMax,1 do
AreaMaterial[x][y][z]=Material
AreaOccupancy[x][y][z]=1
end
end
end
workspace.Terrain:WriteVoxels(Region3.new(Vector3.new(0,0,0),Vector3.new(xVoxelMax,yVoxelMax,zVoxelMax)),4,AreaMaterial,AreaOccupancy)
send me a image of the result
good job
now i want you use a function
and i want the function to take a X and Z position
and you will offset the terrain based on the X and Z position
local function LoadChunk(x, z)
-- load a 16x64x16 chunk of sand like you did above using the X and Z number
end
LoadChunk(0, 0)
LoadChunk(0, 1)
LoadChunk(0, 1)
LoadChunk(1, 0)
LoadChunk(1, 0)
do I just paste the write voxels thing into that?
how do I do that
--offset the 0, 0, 0 and xVoxelMax,yVoxelMax,zVoxelMax
workspace.Terrain:WriteVoxels(Region3.new(Vector3.new(0,0,0),Vector3.new(xVoxelMax,yVoxelMax,zVoxelMax)),4,AreaMaterial,AreaOccupancy)
do I just paste both scripts into the other script
xArrayMax=64
yArrayMax=64
zArrayMax=64
xVoxelMax=xArrayMax4
yVoxelMax=yArrayMax4
zVoxelMax=zArrayMax*4
Material = Enum.Material.Sand
AreaMaterial={}
AreaOccupancy={}
for x=1,xArrayMax,1 do
AreaMaterial[x]={}
AreaOccupancy[x]={}
for y=1,yArrayMax,1 do
AreaMaterial[x][y]={}
AreaOccupancy[x][y]={}
for z=1,zArrayMax,1 do
AreaMaterial[x][y][z]=Material
AreaOccupancy[x][y][z]=1
end
end
end
workspace.Terrain:WriteVoxels(Region3.new(Vector3.new(0,0,0),Vector3.new(xVoxelMax,yVoxelMax,zVoxelMax)),4,AreaMaterial,AreaOccupancy)
oh
this code you sent makes a 64 by 64 by 64 block of sand
i want you to make 5 blocks of sand
using a function
ok
like this
local function LoadChunk(x, z)
-- load a 16x64x16 chunk of sand like you did above using the X and Z number
end
LoadChunk(0, 0)
LoadChunk(0, 1)
LoadChunk(0, 1)
LoadChunk(1, 0)
LoadChunk(1, 0)
does it work
local terrain = workspace:WaitForChild("Terrain")
local chunkSize = 16
local chunkHeight = 4
local regionSize = chunkSize * 4
local regionHeight = chunkHeight * 4
local materials, occupancies = {}, {}
for x = 1, chunkSize do
materials[x], occupancies[x] = {}, {}
for y = 1, chunkHeight do
materials[x][y], occupancies[x][y] = {}, {}
end
end
local function LoadChunk(x, z)
for x = 1, chunkSize do
for y = 1, chunkHeight do
for z = 1, chunkSize do
materials[x][y][z] = Enum.Material.Sand
occupancies[x][y][z] = 1
end
end
end
terrain:WriteVoxels(Region3.new(Vector3.new(x * regionSize, 0, z * regionSize), Vector3.new(x * regionSize + regionSize, regionHeight, z * regionSize + regionSize)), 4, materials, occupancies)
end
LoadChunk(0, 0)
LoadChunk(0, -1)
LoadChunk(0, 1)
LoadChunk(-1, 0)
LoadChunk(1, 0)
this is my version
it doesent work for some reason
my version works
oh you want to continue with your version?
ok
read my version but make your own version
yeah opk
dont copy and paste my version
most likely your not using the character position correctly
ok next thing i want you to do is
make a unload function
ok can I see a example again?
and in that function you will set Material to Air and occupancies to 0
local terrain = workspace:WaitForChild("Terrain")
local chunkSize = 16
local chunkHeight = 4
local regionSize = chunkSize * 4
local regionHeight = chunkHeight * 4
local materials, occupancies = {}, {}
for x = 1, chunkSize do
materials[x], occupancies[x] = {}, {}
for y = 1, chunkHeight do
materials[x][y], occupancies[x][y] = {}, {}
end
end
local function LoadChunk(x, z)
for x = 1, chunkSize do
for y = 1, chunkHeight do
for z = 1, chunkSize do
materials[x][y][z] = Enum.Material.Sand
occupancies[x][y][z] = 1
end
end
end
terrain:WriteVoxels(Region3.new(Vector3.new(x * regionSize, 0, z * regionSize), Vector3.new(x * regionSize + regionSize, regionHeight, z * regionSize + regionSize)), 4, materials, occupancies)
end
-- ADD this function that sets to air and 0
local function UnloadChunk(x, z)
terrain:WriteVoxels(Region3.new(Vector3.new(x * regionSize, 0, z * regionSize), Vector3.new(x * regionSize + regionSize, regionHeight, z * regionSize + regionSize)), 4, materials, occupancies)
end
LoadChunk(0, 0)
LoadChunk(0, -1)
LoadChunk(0, 1)
LoadChunk(-1, 0)
LoadChunk(1, 0)
ok i got it kind of working but its not loading chunks
I think it was because of the player position problem that you said
how do I fix that
ok
well iv given you the hole project now so
you already did that before
step 1 understand the current code
ok lo;
its kinda simple
Ok I will try but I might come back to this help channel
ok
yo suphi I need help
@trail wasp I worked on the script a little and its not making cliffs but it seems to have some perlin noise heres the script:
Im not free for a few days
can you help me though?
Good night
nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
how long until ur free?