#Help adding procedural generation where the player generates chunks

1 messages · Page 1 of 1 (latest)

trail wasp
thin cape
#

where does it get the chunks though

#

and how do I make it generate forever

trail wasp
#

have you installed infinite terrain ?

thin cape
#

yeah

trail wasp
#

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

thin cape
#

so where do I put the generation

trail wasp
thin cape
#

I meant what script do I put it in

trail wasp
#

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

thin cape
#

how do I put my generation into it though

trail wasp
#

i dont know what your generation is

thin cape
#

look at the first thing I sent

#

Here

trail wasp
#

where did you find that script from?

thin cape
#

but its 3d noise does the infinite terrain support that?

thin cape
#

I followed tutorial

trail wasp
#

its a little out of date

thin cape
#

I got it from 3 year old tutorial lol

#

wait does infinite terrain support 3d noise?

trail wasp
#

if i give you a task can you try and do it

thin cape
#

yeah but does infinite terrain support 3d noise

#

because that’s what I’m trying to do

trail wasp
#

to write 64x64x64 voxels of sand

#

once you done that ill tell you the next step

thin cape
#

ok

thin cape
#

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()

trail wasp
#

no

thin cape
#

what

trail wasp
#

thats not what i asked

thin cape
#

what did you ask its 64x64x64 voxels of sand right?

trail wasp
#

no

thin cape
#

wdym

trail wasp
#

i want you to use WriteVoxels

thin cape
#

wait so you want me to make the terrain but without the part?

trail wasp
#

i want you to use WriteVoxels and write 64 x 64 x 64 of sand

thin cape
#

what does writing mean does it mean saving it to somewhere?

trail wasp
#

the world if fullof air voxels

#

and you have to change them to sand

thin cape
#

wait what Im confused

trail wasp
#

use WriteVoxels to make some sand terrain

#

so simple

thin cape
#

oh thats what you mean

#

i think I got something working:
xArrayMax=64
yArrayMax=64
zArrayMax=64

xVoxelMax=xArrayMax4
yVoxelMax=yArrayMax
4
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)

trail wasp
#

send me a image of the result

thin cape
trail wasp
#

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

thin cape
#

like wdym

#

you mean changing the terrains position?

trail wasp
#
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)
thin cape
#

do I just paste the write voxels thing into that?

trail wasp
#

almost

#

you need to shift the Region3

thin cape
#

how do I do that

trail wasp
#

you should end up with 5 chunks loaded like this

trail wasp
# thin cape 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)
thin cape
#

do I just paste both scripts into the other script

trail wasp
# thin cape 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)
thin cape
#

oh

trail wasp
#

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

thin cape
#

ok

trail wasp
#

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)
thin cape
#

i was making it rip

trail wasp
#

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

thin cape
trail wasp
#

my version works

thin cape
#

oh you want to continue with your version?

trail wasp
#

no

#

i want you to learn how to do it

thin cape
#

ok

trail wasp
#

read my version but make your own version

thin cape
#

yeah opk

trail wasp
#

dont copy and paste my version

thin cape
#

ok lol

#

ok i think i got it working but its weird

trail wasp
#

most likely your not using the character position correctly

#

ok next thing i want you to do is

#

make a unload function

thin cape
#

ok can I see a example again?

trail wasp
#

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)
thin cape
#

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

trail wasp
#

i have finished my version

thin cape
#

ok

trail wasp
#

#1138568528056823999 message

#

here is a download

thin cape
#

I cant figure it out rip

#

can we move on or should I figure it out

trail wasp
#

well iv given you the hole project now so

thin cape
#

oh

#

but how will I add 3d perlin noise though

trail wasp
thin cape
#

ik

#

how do I add it to the project

trail wasp
#

step 1 understand the current code

thin cape
#

ok lo;

trail wasp
#

its kinda simple

thin cape
#

Ok I will try but I might come back to this help channel

trail wasp
#

ok

thin cape
#

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:

thin cape
#

can you help me though?

trail wasp
thin cape
#

nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

thin cape
#

how long until ur free?