null nil RBX1 0 0 0 0 1 0 0 0 1 0 0 0 1 Workspace null null 0 7.45296669 138.585358 108.967377 0.898807049 0.350348949 -0.263441622 -0 0.600992203 0.799254835 0.438344479 -0.718375862 0.540176034 70 7.97985029 136.986847 107.887024 1 0 0 0 1 0 0 0 1 Camera true -0.5 0.5 0 0 -0.5 0.5 4 0 194 -2 126 -2 1 0 0 0 1 0 0 0 1 true 0.300000012 0.5 -0.5 0.5 0 0 -0.5 0.5 0 0 true 256 Terrain 0 -0.5 0.5 0 0 0 0 0 -0.5 0.5 3 0 0 0 0 0 2044 252 2044 false Generator 2.0 -- Generator -- By M0RGOTH -- Started 2/9/2013 repeat wait() until _G.Terrain local seed = math.floor(tick()) math.randomseed(seed) print("Generation Seed: "..seed) terrain = _G.Terrain.new() -- Sets up the terrain class with all variables you want custom. Check the terrain class for all the variables. terrain.Setup( { Scale = Vector2.new(70,70); MaxHeight = 70; Incline = 7; WaterHeight = 15; } ) -- The dimentions of each chunk created in the generation process. Should be divisible by terrain.Scale local chunkSize = Vector2.new(10,10) -- If commonDirection is 1, the terrain moves in a general upward direction. If it is -1, it moves in a general downward direction. local commonDirection = 1 function setCommonDirection() if terrain.Incline > math.random(10) then commonDirection = 1 else commonDirection = -1 end end -- Generates a cell at a specific position with a random vertical size. function generateCell(cellPos,chunk) -- Some declarations local adjacentX = terrain.getProximateCell(cellPos,Vector2.new(-1,0)) local adjacentY = terrain.getProximateCell(cellPos,Vector2.new(0,-1)) local followsCommonDirection = true -- Randomization to see if it should continue in a downward/upward direction or if it should be random. if (adjacentX and adjacentX.Part.Size.Y >= terrain.MaxHeight) or (adjacentY and adjacentY.Part.Size.Y >= terrain.MaxHeight) then commonDirection = -1 elseif (adjacentX and adjacentX.Part.Size.Y == 1) or (adjacentY and adjacentY.Part.Size.Y == 1) then commonDirection = 1 else if math.random(100) < 5 then setCommonDirection() end end -- Generate a random vertical size. local verticalSize if not adjacentX and not adjacentY then verticalSize = terrain.StartHeight elseif adjacentX and not adjacentY then local sizeY = math.random(adjacentX.Part.Size.Y,adjacentX.Part.Size.Y + (terrain.Smoothness - 1)) + commonDirection local randomSizeY math.random(adjacentX.Part.Size.Y - terrain.Smoothness,adjacentX.Part.Size.Y + terrain.Smoothness) verticalSize = followsCommonDirection and sizeY or randomSizeY elseif adjacentY and not adjacentX then local sizeY = math.random(adjacentY.Part.Size.Y,adjacentY.Part.Size.Y + (terrain.Smoothness - 1)) + commonDirection local randomSizeY math.random(adjacentY.Part.Size.Y - terrain.Smoothness,adjacentY.Part.Size.Y + terrain.Smoothness) verticalSize = followsCommonDirection and sizeY or randomSizeY elseif adjacentY and adjacentX then local sizeY = math.random((adjacentY.Part.Size.Y + adjacentX.Part.Size.Y)/2,(adjacentY.Part.Size.Y + adjacentX.Part.Size.Y)/2 + (terrain.Smoothness - 1)) + commonDirection local randomSizeY math.random((adjacentY.Part.Size.Y + adjacentX.Part.Size.Y)/2 - terrain.Smoothness,(adjacentY.Part.Size.Y + adjacentX.Part.Size.Y)/2 + terrain.Smoothness) verticalSize = followsCommonDirection and sizeY or randomSizeY end -- Create the cell class and either resize an existing cellPart or make a new one. if adjacentX and adjacentX.Part.Size.Y == verticalSize and adjacentX.CellSize.Y == 1 then cell = terrain.createTerrainCell(cellPos) part = adjacentX.Part terrain.resizeCell(adjacentX,Vector2.new(1,0)) cell.Part = part cell.CellSize = adjacentX.CellSize elseif adjacentY and adjacentY.Part.Size.Y == verticalSize and adjacentY.CellSize.X == 1 then cell = terrain.createTerrainCell(cellPos) part = adjacentY.Part terrain.resizeCell(adjacentY,Vector2.new(0,1)) cell.Part = part cell.CellSize = adjacentY.CellSize else cell = terrain.createTerrainCell(cellPos,true) local part = cell.Part part.Parent = chunk part.Size = Vector3.new(terrain.CellSize.X,verticalSize,terrain.CellSize.Y) part.Position = terrain.cellPositionToWorldPosition(cellPos) + Vector3.new(0,(part.Size.Y/2) - .5,0) if part.Position.Y + (part.Size.Y/2) > terrain.WaterHeight + (terrain.Smoothness*4) then part.BrickColor = BrickColor.new("Bright green") part.Material = "Grass" else part.BrickColor = BrickColor.new("Cool yellow") part.Material = "Concrete" end end end -- Generates a section of terrain with the dimensions set by chunkSize. function generateChunk(start) local chunk = Instance.new("Model",terrain.Container) for row = 1, chunkSize.X do for col = 1, chunkSize.Y do generateCell(Vector2.new(start.X + row,start.Y + col),chunk) end wait() end end -- Generates a piece of terrain based on the parameters set in the terrain class. function generateTerrain() for row = 1, terrain.Scale.X, chunkSize.X do for col = 1, terrain.Scale.Y, chunkSize.Y do generateChunk(Vector2.new(row,col)) end wait() end terrain.createWater() end print("Generation Started at: "..time()) generateTerrain() print("Generation Finished at: "..time()) false Terrain Class -- Terrain Class -- By M0RGOTH -- Started 2/9/2013 local terrain = { Scale = Vector2.new(100,100); MaxHeight = 100; CellSize = Vector2.new(3,3); StartPosition = Vector3.new(10,1,10); Container = nil; Cells = {}; WaterHeight = 10; Smoothness = 1; Incline = 6; StartHeight = 3; } terrain.Setup = function(options) if options then for option,value in pairs(options) do if terrain[option] then terrain[option] = value end end end terrain.Container = Instance.new("Model",workspace) terrain.Container.Name = "Terrain Container" if terrain.Incline > 10 then terrain.Incline = 10 elseif terrain.Incline < 0 then terrain.Incline = 0 end terrain.StartHeight = math.min(terrain.StartHeight,terrain.MaxHeight) end terrain.getProximateCell = function(cellPos,vector) for i = cellPos.X, #terrain.Cells do local newCellPos = terrain.Cells[i].CellPosition if Vector2.new(cellPos.X + vector.X,cellPos.Y + vector.Y) == newCellPos then return terrain.Cells[i] end end end terrain.getCell = function(cellPos) for i = cellPos.X, #terrain.Cells do if terrain.Cells[i].CellPosition == cellPos then return terrain.Cells[i] end end end terrain.cellPositionToWorldPosition = function(cellPos) return Vector3.new(terrain.StartPosition.X + (cellPos.X*terrain.CellSize.X) - (terrain.CellSize.X/2),terrain.StartPosition.Y,terrain.StartPosition.Z + (cellPos.Y*terrain.CellSize.Y) - (terrain.CellSize.Y/2)) end terrain.worldPositionToCellPosition = function(position) return Vector2.new((position.X/terrain.StartPosition.X) - terrain.CellSize.X,(position.Y/terrain.StartPosition.Y) - terrain.CellSize.Y) end terrain.cellSizeToWorldDimensions = function(cellSize) return cellSize * terrain.CellSize end terrain.worldDimensionsToCellSize = function(size) return size / terrain.CellSize end terrain.resizeCell = function(cell,vector) part = cell.Part part.Position = part.Position + Vector3.new((terrain.CellSize.X/2)*vector.X,0,(terrain.CellSize.Y/2)*vector.Y) part.Size = part.Size + Vector3.new(terrain.CellSize.X*vector.X,0,terrain.CellSize.Y*vector.Y) cell.CellSize = cell.CellSize + vector end terrain.createTerrainCell = function(cellPos,createPart) local part if createPart then part = Instance.new("Part",terrain.Container) part.Name = "Part"..#terrain.Cells + 1 part.Anchored = true part.FormFactor = "Symmetric" part.TopSurface = "Smooth" part.BottomSurface = "Smooth" part.Size = Vector3.new(terrain.CellSize.X,1,terrain.CellSize.Y) part.Position = terrain.cellPositionToWorldPosition(cellPos) + Vector3.new(0,(part.Size.Y/2) - .5,0) end local cell = { Part = part; CellPosition = cellPos; CellSize = Vector2.new(1,1); } table.insert(terrain.Cells,cell) return cell end terrain.createWater = function() local water = Instance.new("Part",terrain.Container) water.Name = "Water" water.FormFactor = "Custom" water.BrickColor = BrickColor.new("Bright blue") water.CanCollide = false water.Anchored = true water.Transparency = .5 water.TopSurface = "Smooth" water.BottomSurface = "Smooth" size = terrain.cellSizeToWorldDimensions(terrain.Scale) water.Size = Vector3.new(size.X,.2,size.Y) pos = terrain.cellPositionToWorldPosition(terrain.Scale / 2) water.CFrame = CFrame.new(pos.X + (terrain.CellSize.X*1.5),terrain.WaterHeight,pos.Z + (terrain.CellSize.Y*1.5)) return water end terrain.createTree = function() --TO DO: Create tree end print("Terrain Class Loaded.") _G.Terrain = { --TO DO: Clone the table. new = function() return terrain end; } StarterPack StarterGui true 0 10 1 Soundscape 1 CollectionService PhysicsService BadgeService Geometry RenderHooksService SocialService GamePassService 1000 Debris Instance Instance CookiesService Teleport Service true Players Instance Instance ContextActionService Instance Selection ChangeHistoryService 4286611584 1 4278190080 4278190080 4290822336 100000 0 41.7332993 false Lighting 4289967032 14:00:00