Advertisement
mr2meows

cock

Jul 3rd, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3.  
  4.  
  5. ------------------------------------------------------------------------------------------------------------------------------------------------
  6.  
  7.  
  8.  
  9. local BASE_HEIGHT = 100 -- The main height factor for the terrain.
  10.  
  11. local CHUNK_SCALE = 3 -- The grid scale for terrain generation. Should be kept relatively low if used in real-time.
  12.  
  13. local RENDER_DISTANCE = 50 -- The length/width of chunks in voxels that should be around the player at all times
  14.  
  15. local X_SCALE = 90 -- How much we should strech the X scale of the generation noise
  16.  
  17. local Z_SCALE = 90 -- How much we should strech the Z scale of the generation noise
  18.  
  19. local GENERATION_SEED = math.random() -- Seed for determining the main height map of the terrain.
  20.  
  21. local TERRAIN_TYPE = Enum.Material.Ice --Terrain Type
  22.  
  23.  
  24.  
  25. ------------------------------------------------------------------------------------------------------------------------------------------------
  26.  
  27.  
  28.  
  29. local chunks = {} --table to store chunk locations
  30.  
  31.  
  32.  
  33. --Checks player location to see if they have already been there
  34.  
  35. --If it is a new location, it adds to table
  36.  
  37. local function chunkExists(chunkX, chunkZ)
  38.  
  39. if not chunks[chunkX] then
  40.  
  41. chunks[chunkX] = {}
  42.  
  43. end
  44.  
  45. return chunks[chunkX][chunkZ]
  46.  
  47. end
  48.  
  49.  
  50.  
  51. --Takes calculated values and generates terrain
  52.  
  53. local function mountLayer(x, heightY, z, material)
  54.  
  55. local beginY = -BASE_HEIGHT
  56.  
  57. local endY = heightY
  58.  
  59. local cframe = CFrame.new(x * 4 + 2, (beginY + endY) * 4 / 2, z * 4 + 2)
  60.  
  61. local size = Vector3.new(4, (endY - beginY) * 4, 4)
  62.  
  63. workspace.Terrain:FillBlock(cframe, size, material)
  64.  
  65. end
  66.  
  67.  
  68.  
  69. --Prepares values for terrain generation
  70.  
  71. function makeChunk(chunkX, chunkZ)
  72.  
  73. local rootPosition = Vector3.new(chunkX * CHUNK_SCALE, 0, chunkZ * CHUNK_SCALE)
  74.  
  75. chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance.
  76.  
  77. for x = 0, CHUNK_SCALE - 1 do
  78.  
  79. for z = 0, CHUNK_SCALE - 1 do
  80.  
  81. local cx = (chunkX * CHUNK_SCALE) + x
  82.  
  83. local cz = (chunkZ * CHUNK_SCALE) + z
  84.  
  85. local noise = math.noise(GENERATION_SEED, cx / X_SCALE, cz / Z_SCALE)
  86.  
  87. local cy = noise * BASE_HEIGHT
  88.  
  89. mountLayer(cx, cy, cz, TERRAIN_TYPE) --sends values to mountLayer function
  90.  
  91. end
  92.  
  93. end
  94.  
  95. end
  96.  
  97.  
  98.  
  99.  
  100.  
  101. --Checks player surroundings
  102.  
  103. --Adds location to table
  104.  
  105. --Adds new terrain as player moves to new locations
  106.  
  107. function checkSurroundings(location)
  108.  
  109. local chunkX, chunkZ = math.floor(location.X / 4 / CHUNK_SCALE), math.floor(location.Z / 4 / CHUNK_SCALE)
  110.  
  111. local range = math.max(1, RENDER_DISTANCE / CHUNK_SCALE)
  112.  
  113. for x = -range, range do
  114.  
  115. for z = -range, range do
  116.  
  117. local cx = chunkX + x
  118.  
  119. local cz = chunkZ + z
  120.  
  121. if not chunkExists(cx, cz) then --sends player location area to chunkExist function
  122.  
  123. makeChunk(cx, cz) --If player is in a new area it will make terrain
  124.  
  125. end
  126.  
  127. end
  128.  
  129. end
  130.  
  131. end
  132.  
  133.  
  134.  
  135. --Main Loop
  136.  
  137. --Gets player location every 1 second
  138.  
  139. while true do
  140.  
  141. for _, player in pairs(Players:GetPlayers()) do
  142.  
  143. if player.Character then
  144.  
  145. local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
  146.  
  147. if humanoidRootPart then
  148.  
  149. checkSurroundings(humanoidRootPart.Position) --sends player location to checkSurroundings function
  150.  
  151. end
  152.  
  153. end
  154.  
  155. end
  156.  
  157. wait(1)
  158.  
  159. end
  160. game.Workspace.Base:Destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement