Help with smoothing out terrain generated with script

Hello there!
I recently got interested in the topic of Perlin noise and terrain generation so after a bit of research I messed around in studio and made a script that generates random terrain

After narrowing down how I wanted my terrain to look, I was confronted with the fact that the terrain is infact not smooth and bumpy, it looks ok with grass but without it…

Ive seen on devfourm a few posts showing other people finding solutions to this such as increasing part size (which i tried), and switching to other methods besides FillBlock (which im using) such as FillCircle (also tried) and WriteVoxels

Im asking for help because I am completely new to terrain, literally first time ever using it, so attempting to look at other solutions was difficult or confusing for me.

Here is the script im using

local TerrainSizeX = 500 -- length
local TerrainSizeZ = 1000 -- width
local resolution = 6000 -- how zoomed in or smooth it looks
local frequency = 8 -- how often it makes something cool (1 is less 10 is more)
local amplitude = 150 -- how high / how steep
local seed = math.random(-100000000,100000000)
seed = 100000000
workspace.Terrain:Clear()
task.wait(1)

local function getHeight(x,z)
	local noiseHeight = math.noise((x+seed)/resolution*frequency,(z+seed)/resolution*frequency)
	noiseHeight = math.clamp(noiseHeight,-0.2,0.35) +0.2
	
	return noiseHeight
end

local function genTerrain(pos)
	--workspace.Terrain:FillBlock(CFrame.new(pos),Vector3.new(1,1,1),Enum.Material.Ground)
	workspace.Terrain:FillBall(pos,2,Enum.Material.Ground)
end

local function genPart(pos)
	local part = Instance.new("Part")
	part.Size = Vector3.new(1,1,1)
	part.Anchored = true
	part.Position = pos
	part.Parent = workspace.Folder
end

for x = -TerrainSizeZ/2, TerrainSizeZ/2 do
	task.spawn(function()
		for z = 0, TerrainSizeZ do
			local height = getHeight(x*4,z*4)		
			local pos = Vector3.new(x*4,height*amplitude,z*4)
			genTerrain(pos)
			--genPart(pos)
			task.wait()
		end
	end)
	--break
end

Any help would be greatly appreciated, for reference I’m trying to make the terrain smooth like this

1 Like

The issue is most likely due to when passing seed, it is enormous and offsets the noise to areas where floating point errors become huge. Try moving the seed to the third argument in noise instead of adding it to x and z.

Unless this has something to do with terrain just being very blocky at all times, in which case idk really.

Use should look into Terrain methods which allow you to explicitly write the Occupancy of voxels. For example, Terrain:WriteVoxels and Terrain:WriteVoxelChannels - I recommend the latter if you’ll be dealing with Water when generating terrain.

I hate to admit that doing that little change literally fixed it, everything is smooth now except for when your far away then roblox does weird rendering stuff but if you move closer its all smooth now and its still randomized terrain!



Now I just gotta figure out if theres a way to force it to render detail from a farther distance

2 Likes