I have a procedural generation code that works perfectly. The only problem is that it only works in generating once in one spot. I would like to make it load like how Minecraft loads chunks(Dont worry im not copying the game just tryna get some experience) where the chunks change there "terrain" based on their position. What im trying to say is im not sure what part of the code to change to simulate the chunk being in a different position to where itll be different. Basically trying to break up a map into 16x16 chunks so that i dont have to render the map all at once(since its super slow to do that). The blocks are 4x4x4 cubes. Here is the module script:
local GenTerrain = {}
function GenTerrain.Gen(Freq,Power)
local Seed = math.random(1, 10e6)
local MapLimit = 1000
local Size = 16
local RenderDistance = 3
local function RoundY(YVal)
local NewVal = math.floor(YVal)
local Diff = NewVal % 4
return NewVal - Diff
end
for T = 1,RenderDistance do
for T2 = 1,RenderDistance do
wait()
for X = 1,Size do
for Z = 1,Size do
local Y1 = math.noise(
(X*Freq)/MapLimit,
(Z*Freq)/MapLimit,
Seed
)
local Y2 = math.noise(
(X*Freq*.125)/MapLimit,
(Z*Freq*.125)/MapLimit,
Seed
)
local Y3 = math.noise(
(X*Freq*4)/MapLimit,
(Z*Freq*4)/MapLimit,
Seed
)
local HeightVal = (Y1*Y2*Power*Power)+Y3
local Block = Instance.new("Part")
Block.Size = Vector3.new(4,4,4)
Block.Parent = workspace.Blocks
Block.BrickColor = BrickColor.new("Earth green")
Block.Anchored = true
Block.CFrame = CFrame.new(X*4+((T-1)*16*4),RoundY(HeightVal),Z*4+((T2-1)*16*4))
local NumTimes = (Block.Position.Y + 10) / 4
for i = 1,NumTimes do
local Block2 = Instance.new("Part")
Block2.Parent = workspace.UnderGroundBlocks
Block2.BrickColor = BrickColor.new("Dirt brown")
Block2.Size = Vector3.new(4,4,4)
Block2.CFrame = CFrame.new(Block.Position.X,Block.Position.Y - i*4,Block.Position.Z)
Block2.Anchored = true
end
end
end
end
end
end
return GenTerrain

1 comment
Oh my that actually answered my question perfectly and it works! Thank you so much!