Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local baseHeight = 29 -- The main height factor for the terrain.
- local chunkScale = 12 -- The grid scale for terrain generation. Should be kept relatively low if used in real-time.
- local renderDist = 180/4 -- The length/width of chunks in voxels that should be around the player at all times
- local xScale = 95/4 -- How much we should strech the X scale of the generation noise
- local zScale = 95/4 -- How much we should strech the Z scale of the generation noise
- local generationSeed = math.random() -- Seed for determining the main height map of the terrain.
- ------------------------------------------------------------------------------------------------------------------------------------------------
- local chunks = {}
- function chunkExists(chunkX,chunkZ)
- if not chunks[chunkX] then
- chunks[chunkX] = {}
- end
- return chunks[chunkX][chunkZ]
- end
- function mountLayer(x,heightY,z,material)
- local begY = -baseHeight
- local endY = heightY
- workspace.Terrain:FillBlock(CFrame.new(x*4+2, (begY+endY)*4/2, z*4+2), Vector3.new(4, (endY-begY)*4, 4), material)
- end
- function makeChunk(chunkX,chunkZ)
- local rootPos = Vector3.new(chunkX*chunkScale,0,chunkZ*chunkScale)
- chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance.
- for x = 0,chunkScale-1 do
- for z = 0,chunkScale-1 do
- local cx = (chunkX*chunkScale) + x
- local cz = (chunkZ*chunkScale) + z
- local noise = math.noise(generationSeed,cx/xScale,cz/zScale)
- local cy = noise*baseHeight
- local Z = math.random(0,20)
- if Z == 1 then
- Choice = Enum.Material.Grass
- elseif Z == 2 then
- Choice = Enum.Material.Grass
- elseif Z == 3 then
- Choice = Enum.Material.Grass
- elseif Z == 4 then
- Choice = Enum.Material.Grass
- elseif Z == 5 then
- Choice = Enum.Material.Grass
- elseif Z == 6 then
- Choice = Enum.Material.Grass
- elseif Z == 7 then
- Choice = Enum.Material.Grass
- elseif Z == 8 then
- Choice = Enum.Material.Rock
- elseif Z == 9 then
- Choice = Enum.Material.Ground
- elseif Z == 10 then
- Choice = Enum.Material.Grass
- elseif Z == 11 then
- Choice = Enum.Material.Rock
- elseif Z == 12 then
- Choice = Enum.Material.Ground
- elseif Z == 13 then
- local Lemon = "Potato"
- elseif Z == 14 then
- Choice = Enum.Material.Grass
- elseif Z == 15 then
- Choice = Enum.Material.Grass
- elseif Z == 16 then
- Choice = Enum.Material.Grass
- elseif Z == 17 then
- Choice = Enum.Material.Grass
- elseif Z == 18 then
- Choice = Enum.Material.Ground
- elseif Z == 19 then
- Choice = Enum.Material.Grass
- elseif Z == 20 then
- Choice = Enum.Material.Rock
- end
- mountLayer(cx,cy,cz,Choice)
- mountLayer(cx,cy-2,cz,Choice)--Makes sure u cant fall and die
- end
- end
- end
- function checkSurroundings(location)
- local chunkX,chunkZ = math.floor(location.X/4/chunkScale),math.floor(location.Z/4/chunkScale)
- local range = math.max(1,renderDist/chunkScale)
- for x = -range,range do
- for z = -range,range do
- local cx,cz = chunkX + x,chunkZ + z
- if not chunkExists(cx,cz) then
- makeChunk(cx,cz)
- end
- end
- end
- end
- while true do
- for _,player in pairs(game.Players:GetPlayers()) do
- if player.Character then
- local torso = player.Character:FindFirstChild("Torso")
- if torso then
- checkSurroundings(torso.Position)
- end
- end
- end
- wait(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement