Perlin Noise Caves

I have been trying to make caves but it always has resulted in a 2d sort of cave

function density(p: Vector3, frequency): number
	return math.noise(
		p.X * frequency,
		p.Y * frequency,
		p.Z * frequency
	)
end

for y = 1,16 do
		for x = 1,16 do
			for z = 1,16 do
				local threshold = 0
				local frequency = 1/4
				local d = density(Vector3.new(x+(WorldSeed),y+v.ChunkStats.Offset.Value.Y,z + v.ChunkStats.Offset.Value.Z),frequency)
				if d < threshold then
					Blocks[y][x][z] = nil
				end
			end
		end
	end

Note the 2nd part of the code is for overwriting block placement

Try implementing perlin worms. (This is how minecraft generated caves (im not sure if they still use this method))

Thanks but the major issue with that is that mine is a chunk based generation system and the perlin worms don’t exactly work well with that sort of generation system. I am right now trying to figure out 3D perlin noise

Sorry but I don’t think i’ll be able to provide any further help as my knowledge on this topic isn’t that great. Best of luck with your system :slight_smile:

This is my version of perlin worms in Lua U:

local Workspace = game:GetService("Workspace")
local spawnPlace = Workspace

local seed = 1000
local blockSize = 4
local startingCFrame = CFrame.new(0, 0, 0)
local wormCurvature = 0.9

local function newBlock(targetCFrame)
	local block = Instance.new("Part")
	block.CFrame = targetCFrame
	block.Size = Vector3.new(blockSize, blockSize, blockSize)
	block.Anchored = true
	block.Parent = Workspace

	return block
end

for blocksSpawned = 1, 100, 1 do
	local xNoise = math.noise((startingCFrame.Y + 2313.682) * wormCurvature, (startingCFrame.Z + 6721.123) * wormCurvature, seed)
	local yNoise = math.noise((startingCFrame.X + 4432.572) * wormCurvature, (startingCFrame.Z - 8742.941) * wormCurvature, seed)
	local zNoise = math.noise((startingCFrame.X - 5472.377) * wormCurvature, (startingCFrame.Y - 1049.189) * wormCurvature, seed)
	local noise = Vector3.new(xNoise, yNoise, zNoise)
	
	newBlock(startingCFrame)
	
	startingCFrame += CFrame.lookAlong(startingCFrame.Position, noise).LookVector * blockSize
end