SHOW:
|
|
- or go back to the newest paste.
| 1 | local chunks = {}
| |
| 2 | local player = game.Players.LocalPlayer | |
| 3 | local char = player.Character | |
| 4 | local torso = char:WaitForChild("Torso")
| |
| 5 | ||
| 6 | - | local baseHeight = 10 -- The main height factor for the terrain. |
| 6 | + | local baseHeight = 50 -- The main height factor for the terrain. |
| 7 | - | local chunkScale = 3 -- The grid scale for terrain generation. Should be kept relatively low if used in real-time. |
| 7 | + | local chunkScale = 30 -- The grid scale for terrain generation. Should be kept relatively low if used in real-time. |
| 8 | local renderDist = 120 -- The length/width of chunks in voxels that should be around the player at all times | |
| 9 | - | local xScale = 90 -- How much we should strech the X scale of the generation noise |
| 9 | + | local xScale = 190 -- How much we should strech the X scale of the generation noise |
| 10 | - | local zScale = 90 -- How much we should strech the Z scale of the generation noise |
| 10 | + | local zScale = 190 -- How much we should strech the Z scale of the generation noise |
| 11 | ||
| 12 | local generationSeed = math.random() -- Seed for determining the main height map of the terrain. | |
| 13 | local mountainSeed = math.random() -- Seed for determining if we should make mountains. | |
| 14 | ||
| 15 | function chunkExists(chunkX,chunkZ) | |
| 16 | if not chunks[chunkX] then | |
| 17 | chunks[chunkX] = {}
| |
| 18 | end | |
| 19 | return chunks[chunkX][chunkZ] | |
| 20 | end | |
| 21 | ||
| 22 | function mountLayer(x,heightY,z,material) | |
| 23 | local x = math.floor(x/4) | |
| 24 | local z = math.floor(z/4) | |
| 25 | for y = -baseHeight,heightY do | |
| 26 | workspace.Terrain:SetCell(x,y,z,material,0,0) | |
| 27 | end | |
| 28 | end | |
| 29 | ||
| 30 | function makeChunk(chunkX,chunkZ) | |
| 31 | local rootPos = Vector3.new(chunkX*chunkScale,0,chunkZ*chunkScale) | |
| 32 | chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance. | |
| 33 | for x = 0,chunkScale-1 do | |
| 34 | for z = 0,chunkScale-1 do | |
| 35 | local cx = (chunkX*chunkScale) + x | |
| 36 | local cz = (chunkZ*chunkScale) + z | |
| 37 | local noise = math.noise(generationSeed,cx/xScale,cz/zScale) | |
| 38 | local material = noise < 0 and 1 or 4 | |
| 39 | local cy = noise*baseHeight*material | |
| 40 | mountLayer(cx,cy,cz,material) | |
| 41 | end | |
| 42 | end | |
| 43 | end | |
| 44 | ||
| 45 | while true do | |
| 46 | local chunkX,chunkZ = math.floor(torso.Position.X/chunkScale),math.floor(torso.Position.Z/chunkScale) | |
| 47 | local range = math.max(1,renderDist/chunkScale) | |
| 48 | for x = -range,range do | |
| 49 | for z = -range,range do | |
| 50 | if not (x == 0 and z == 0) then | |
| 51 | local cx,cz = chunkX + x,chunkZ + z | |
| 52 | if not chunkExists(cx,cz) then | |
| 53 | makeChunk(cx,cz) | |
| 54 | end | |
| 55 | end | |
| 56 | end | |
| 57 | end | |
| 58 | wait() | |
| 59 | end |