Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chunks = {}
- local player = game.Players.LocalPlayer
- local char = player.Character
- local torso = char:WaitForChild("Torso")
- local baseHeight = 10 -- The main height factor for the terrain.
- local chunkScale = 3 -- The grid scale for terrain generation. Should be kept relatively low if used in real-time.
- local renderDist = 120 -- The length/width of chunks in voxels that should be around the player at all times
- local xScale = 90 -- How much we should strech the X scale of the generation noise
- local zScale = 90 -- 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 mountainSeed = math.random() -- Seed for determining if we should make mountains.
- function chunkExists(chunkX,chunkZ)
- if not chunks[chunkX] then
- chunks[chunkX] = {}
- end
- return chunks[chunkX][chunkZ]
- end
- function mountLayer(x,heightY,z,material)
- local x = math.floor(x/4)
- local z = math.floor(z/4)
- for y = -baseHeight,heightY do
- workspace.Terrain:SetCell(x,y,z,material,0,0)
- end
- 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 material = noise < 0 and 1 or 4
- local cy = noise*baseHeight*material
- mountLayer(cx,cy,cz,material)
- end
- end
- end
- while true do
- local chunkX,chunkZ = math.floor(torso.Position.X/chunkScale),math.floor(torso.Position.Z/chunkScale)
- local range = math.max(1,renderDist/chunkScale)
- for x = -range,range do
- for z = -range,range do
- if not (x == 0 and z == 0) then
- local cx,cz = chunkX + x,chunkZ + z
- if not chunkExists(cx,cz) then
- makeChunk(cx,cz)
- end
- end
- end
- end
- wait()
- end
- --------------------------------------------------
- local region = Region3.new(Vector3.new(-1250,0,-1250), Vector3.new(1250,18,1250))
- region = region:ExpandToGrid(4)
- game.Workspace.Terrain:FillRegion(region, 4, Enum.Material.Water)
- --------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement