How to make a terrain generator in roblox code example
Example: How to make a terrain generator in roblox
--[[ all code by okeanskiy. ]]--
--[[
Script #1 of 2: game.ServerScriptService.Terrain (Server Script)
]]
local X = 50
local Z = 50
local grid = {}
for x = 1, X do
grid[x] = {}
for z = 1, Z do
grid[x][z] = math.noise(x/10, z/10) * 15
end
end
for x = 1, X do
for z = 1, Z do
local yPos = grid[x][z]
local part = Instance.new("Part")
part.Anchored = true
if yPos < -3 then
part.Material = Enum.Material.Sand
part.BrickColor = BrickColor.new("Cool yellow")
else
part.Material = Enum.Material.Grass
part.BrickColor = BrickColor.new("Bright green")
end
part.Position = Vector3.new(x*5, yPos, z*5)
part.Size = Vector3.new(5, 30, 5)
part.Parent = workspace
end
end
local water = Instance.new("Part")
water.Anchored = true
water.Size = Vector3.new(X*5, 30, Z*5)
water.Position = Vector3.new(((X+1)*5)/2, -5, ((Z+1)*5)/2)
water.CanCollide = false
water.Transparency = .5
water.BrickColor = BrickColor.new("Electric blue")
water.Parent = workspace
--[[
Script #2 of 2: game.ServerScriptService.RandomVsNoise (Server Script)
]]
print("10 RANDOM NUMBERS:")
for i = 1, 10 do
print(math.random())
end
print("10 NUMBERS GENERATED FROM NOISE")
for i = 1, 10 do
print(math.noise(i/10))
end