Help with converting 2D perlin noise to 3D perlin noise

I am currently creating a game that’s like old Minecraft and I have a chunk system that utilizes 2D perlin noise however, I want to have hangovers which means I have to convert it to 3D perlin noise.

I am having trouble on figuring out how to convert my 2D perlin noise chunk generator into 3D perlin noise. I have listed the code that I think will be the most useful for help below:

local ChunkRenderDistance = 8
local ChunkSize = 16
local ChunkGrid = {}
local CurrentBiome = 4
local Seed = math.random(1, 9999)

local blocks = game.Workspace.Blocks

local uis = game:GetService("UserInputService")

local Biomes = {
	--{'Mountains' ,80, 70},
	{'Plains' ,70, 26},
	{'Forest' ,70, 26},
	{'Desert' ,70, 26},
	{'Rivers' ,70, 26},
}

function GenerateNewChunk(Position)
	if math.random(1,100) == 1 then CurrentBiome = math.random(1, #Biomes) print('Changed') end 
	local Frequency = Biomes[CurrentBiome][2]
	local Amplitude = Biomes[CurrentBiome][3]

	local ChunkData = {}
	for x = 1, ChunkSize do
		ChunkData[x] = {}
		local LastYPos = 0
		for z = 1, ChunkSize do
			local X = ((x * 3) + Position.X + 1.5)
			
			local Y = ((math.floor((math.noise(((x * 3) + Position.X + 1.5) / Frequency, ((z * 3) + Position.Z + 1.5) / Frequency, Seed) * Amplitude) / 3) * 3) + 1.5)
			local Z = ((z * 3) + Position.Z + 1.5)
			
			
			ChunkData[x][z] = Vector3.new(X, Y, Z)
			LastYPos = Y
		end
	end

	table.insert(ChunkGrid, {Position ,ChunkData})
	return {Position ,ChunkData}
end
1 Like

I would break up that huge local Y = line first to make it easier to understand. You need to add one more layer of for loop and then you will have X Y Z and W assignments in the middle. The W will be the value at the 3D point XYZ.

1 Like

I’m unsure of how I would go about doing that, how exactly would I break up the local y =…?

1 Like