# Make terrain more natural?

Hello,

I’ve been working on a procedural terrain generator for a big project i have coming. I finished the generator but i have an issue with Roblox terrain, it sticks out in weird lines which make it look unnatural:

This isn’t some render optimization issue because it still retains the lines when the camera is close and the quality level is set to max.

Perlin noise generator
``````function Noise2D.new(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
local self = Map2D.new(WidthX, WidthZ)

local MaxHeight = -math.huge
local MinHeight = math.huge

for X = 0, WidthX do
for Z = 0, WidthZ do

local Amplitude = 5
local Frequency = 1
local Height = 0

for Index = 0, Octaves do
local SampleX = X / Scale * Frequency
local SampleZ = Z / Scale * Frequency

local Noise = math.noise(SampleX, SampleZ, Seed)
Height += Noise * Amplitude

Amplitude *= Persistance
Frequency *= Lacunarity
end
if Height > MaxHeight then
MaxHeight = Height
elseif Height < MinHeight then
MinHeight = Height
end

self[X][Z] = Height
end
end

for X = 0, WidthX do
for Z = 0, WidthZ do
self[X][Z] = InverseLerp(MinHeight, MaxHeight, self[X][Z]) * Amplitude
end
end

return self
end
``````
Terrain script
``````local function Generate(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
local Map = Noise2D.new(WidthX, WidthZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity)
for X = 0, WidthX do
for Z = 0, WidthZ do
local Y = Map[X][Z]
local Block = CFrame.new(Vector3.new(X, Y, Z))
Terrain:FillBlock(Block, Vector3.new(2, 5, 2), Enum.Material.Grass)
end
RunService.Heartbeat:Wait()
end
end

Generate(1000, 1000, math.random(), 200, 50, 20, 10, 10, 1)
-- SizeX, SizeZ, Seed, Scale, Amplitude, Frequency, Octaves, Persistance, Lacunarity --
``````

Any help is appreciated!

4 Likes

I have the same issue too! Did you ever find the fix to this?

1 Like

Not yet, I hope someone finds a solution in the future.

A fix for this is by making the value/height generated from math.noise smoothed out by the surrounding heights of the terrain arround it, for example;
If you check perlin noise in a area if 3x3:
0.5 - 0.6 - 0.7
0.5 - 0.6 - 0.7
0.4 - 0.5 - 0.6
You combine all those numbers and divide them, so; (0.5 + 0.6 + 0.7 + 0.5 + 0.6 + 0.7 + 0.4 + 0.5 + 0.6)\9 = 0.56

So your noise output is 0.56 and if you do that for every piece of terrain you get a nice smooth output

I really just smoothen them out, as right now, we can’t really find a solution. It’s hard work, but you gotta do something?

This doesn’t fix it. this is an issue with Roblox terrain. Your method is also inefficient and slow, it’s basically adding more/less octaves

Well, this is how I do it for my terrain and it works flawlessly without any lag.
Obviously there are better ways to doing this, but this is my way of doing this.

There is a built in terrain generator you can use!

I created my own because Roblox doesn’t provide a built-in terrain generator in a live server.

1 Like