So ive been making a terrain generator. I know it isnt the right way but i dont understand the right way at all. Can you please give me ideas about how to make terrain generation or how to improve my script?
This is what my really strange looking hills terrain looks like.
Here is the script aswell:
wait(3)
local prevgrassblocklevel = 61
while prevgrassblocklevel % 3 ~= 0 do
local prevgrassblocklevel = math.random(60,70)
if prevgrassblocklevel % 3 == 0 then
break
end
end
local function CreateChunk(x,z,biome)
local block = ""
local maxheight = 69
if biome == "Plains" then
maxheight = 60
block = "GrassBlock"
elseif biome == "Hills" then
maxheight = 72
block = "GrassBlock"
elseif biome == "Rocks" then
maxheight = 66
block = "StoneBlock"
end
for e = 1,48 do
if e % 3 == 0 then
for i = 1,48 do
if i % 3 == 0 then
local bedrocklevel = CFrame.new(i + x,0,e + z)
local grasslvlismultiple = false
local grasslevel
while grasslvlismultiple == false do
grasslevel = bedrocklevel * CFrame.new(0,math.random(60,maxheight),0)
if grasslevel.Y % 3 == 0 and grasslevel.Y - prevgrassblocklevel <= 3 then
break
end
end
prevgrassblocklevel = grasslevel.Y
local bedrock = game.ReplicatedStorage.GenerationBlocks.BedRock:Clone()
local grass = game.ReplicatedStorage.GenerationBlocks:WaitForChild(block):Clone()
bedrock.Parent = workspace.Blocks
grass.Parent = workspace.Blocks
bedrock.CFrame = bedrocklevel
grass.CFrame = grasslevel
-- fill
for r = 1,grasslevel.Y - 1 do
if r % 3 == 0 then
local fillblock = ""
local fillblocks = {"StoneBlock"}
if r >= 54 then
if biome ~= "Plains" and biome ~= "Hills" then
fillblock = "StoneBlock"
else
fillblock = "DirtBlock"
end
else
fillblock = fillblocks[math.random(1,1)]
end
local fillblockreal = game.ReplicatedStorage.GenerationBlocks:WaitForChild(fillblock):Clone()
fillblockreal.Parent = workspace.Blocks
fillblockreal.CFrame = bedrocklevel * CFrame.new(0,r,0)
end
end
end
end
end
end
end
It actually works well but i just dont like how the terrain doesnt look smooth.