Z_Dev

map generation

Jan 12th, 2022
1,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. local seed = math.random(1,1000)
  2.  
  3. local MAPSIZE = 300
  4. local MAPHEIGHT = 8 -- Increasing the map height might break the game
  5.  
  6. local chunks = {}
  7.  
  8. local MAPSCALE = MAPSIZE/2
  9.  
  10.  
  11. local maxTrees = 100 * MAPSIZE
  12.  
  13. local function generateTrees(block)
  14.    
  15.  
  16.         local tree = script.Parent.Tree:Clone()
  17.         tree.Parent = game.Workspace.Trees
  18.         tree:SetPrimaryPartCFrame(block.CFrame)
  19.  
  20.    
  21.     -- result
  22.     return block
  23. end
  24. for x = MAPSCALE-MAPSCALE-MAPSCALE, MAPSCALE do
  25.     for z = MAPSCALE-MAPSCALE-MAPSCALE, MAPSCALE do
  26.         local noise = math.noise(seed, x/20,z/20)*MAPHEIGHT
  27.         local block = script.Parent.Block:Clone()
  28.         block.Position = Vector3.new(x*4,math.floor(noise)*4,z*4)
  29.         block.Parent = game.Workspace.MapGeneration
  30.        
  31.         if block.Position.Y > 5 then
  32.             -- Brown
  33.             block.Color = Color3.fromRGB(97, 97, 97)
  34.         elseif block.Position.Y >= -1 then
  35.             block.Color = Color3.fromRGB(65, 38, 0)
  36.            
  37.         elseif block.Position.Y < -4 then
  38.             block.Color = Color3.fromRGB(255, 226, 158)
  39.         end
  40.         -- SNOW
  41.        
  42.         if block.Position.Y >= 16 then
  43.             block.Color = Color3.new(1, 1, 1)
  44.            
  45.         end
  46.         table.insert(chunks, block)
  47.     end
  48. end
  49. for i = 1,maxTrees-1,1 do
  50.     local randomBlock = game.Workspace.MapGeneration:GetChildren()[math.random(1,#game.Workspace.MapGeneration:GetChildren())]
  51.  
  52.     generateTrees(randomBlock)
  53. end
  54.  
Advertisement
Add Comment
Please, Sign In to add comment