Attempting to make a 3d terrain gen cave system somewhat like minecraft

I have been experimenting with 2d noise converting it to terrain for the past month or so, and i am wanting to take a step forward. But said step is a hard step to take. And i am requesting help in getting to that step/a push along.

Little diagram of what i am attempting to do:


White being hollow,
Black being filled.

(Once again i am coming into this with a intermediate level of knowledge of math.noise)

1 Like

Also a general explanation on how to make a 3d array (Which is what i assume is needed)

1 Like

There’s quite a few threads on this, you might find something useful if you search.

The basic idea is something like this:

function getPointDensity(x, y, z)
    return DENSITY_AMPLITUDE * math.noise(
        x / DENSITY_PERIOD,
        y / DENSITY_PERIOD,
        z / DENSITY_PERIOD
    ) + DENSITY_BASELINE
end

for x = 1, MAP_SIZE do
    for y = 1, MAP_SIZE do
        for z = 1, MAP_SIZE do
            local density = getPointDensity(x, y, z)
            if density >= DENSITY_THRESHOLD then
                placeBlockAt(x, y, z)
            end
        end
    end
end