Perlin noise & Caves

Hi there,

I’m not the best at using perlin noise, mathematically wise. However, how would you make caves off a basic perlin-noise terrain?

Here’s a “test-code”, that I’ll make it better in the future, and turn it into a triangle map.

local p = workspace:WaitForChild('Part');
p.Anchored = true; 

local folder = Instance.new'Folder'; 
folder.Parent = workspace;
folder.Name = 'Parts'; 

local f = 67
local coeff = 450; 

function calc(x,z,o)
	local height = 0; 
        local r = math.random(8,8*2);
	for i = 1, r do
		height = height + math.noise(x/(coeff/i)+o,z/(coeff/i)+o); 
	end
	height = height/r; 
	return height; 
end

for i = 1, 450 do
	for j = 1, 450 do
		local new = p:Clone(); 
		new.Parent = folder; 
		new.Position = Vector3.new(i*new.Size.x, 0+coeff*calc(i,j,f), j*new.Size.z); 
	end
end

game.Debris:AddItem(p,0);
6 Likes

I don’t know the specifics for part/heightmap terrain (probably a fair bit harder to do) but I do know the specifics for voxel terrain, e.g. smooth terrain.

Personally I use perlin worms. They make for really convincing cave systems!

Here’s an example from a decidedly more blocky voxel engine:

The idea is to create a point in space which randomly moves around, destroying everything in a radius around it. You can vary the radius as well to get a more convincing effect. To do the randomisation, you can use perlin noise to create smoothly changing random values.

Hopefully this at least partially helps you find a solution for your heightmapped terrain generator :slight_smile:

15 Likes

Thanks,

had no idea how to start, at least now I do. The randomly moving part idea is awesome, :0

2 Likes

yeah, when I first saw it I was pretty impressed too. If you want to see what it might look like in a Roblox implementation, I actually used this technique to generate caves in Project Vox.

5 Likes

You did an awesome job on that.

2 Likes

You might also wanna take a look at 3D perlin noise. It can possibly be used to create nice caves as well:

7 Likes

As my final map generator will be made of triangles, I’d rather go for the first way. Although perlin 3d looks awesome for other kind of maps.

2 Likes

Alright, good luck!

2 Likes