Dirt exposed on terrain surface (Perlin noise)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Dirt hidden from terrain surface

  2. What is the issue?
    image

  3. What solutions have you tried so far? Changing values and operators Did you look for solutions on the Developer Hub? No

Here is the script for terrain generation

local cache = workspace.Cache -- Folder

local length = 50
local width = length
local height = 50

local size = 4

local resolution = 50
local amplitude = 5
local frequency = 2
local seed = Random.new():NextInteger(0,10000)

for x = 0, length do
    for y = 0, height do
        if y == 10 then task.wait() end
         for z = 0, width do
            local xNoise = math.noise(y/resolution*frequency,z/resolution*frequency,seed)*amplitude
            local yNoise = math.noise(x/resolution*frequency,z/resolution*frequency,seed)*amplitude
            local zNoise = math.noise(x/resolution*frequency,y/resolution*frequency,seed)*amplitude
            
            local density = math.floor(xNoise + yNoise + zNoise + y)
            
            if density <= 20 then
                local part = Instance.new("Part")
                part.Size = Vector3.new(size,size,size)
                part.Position = Vector3.new(x*size,y*size,z*size)
                part.Material = Enum.Material.SmoothPlastic
                part.Anchored = true
                part.Parent = cache
                if density <= 20 and density >= 19 then
                    part.BrickColor = BrickColor.new("Forest green")
                    --createPart(x,y,z,"Forest green") 
                elseif density <= 19 and density >= 16 then
                    part.BrickColor = BrickColor.new("CGA brown")
                    --createPart(x,y,z,"CGA Brown")
                elseif density < 16 then
                    part.BrickColor = BrickColor.new("Medium stone grey")
                    --createPart(x,y,z,"Medium Stone Grey")
                end
            end
        end
    end
    task.wait()
end
1 Like

what i did to create dirt under grass was to check if the noise(x,y+1,z) (or plus however large your grid is) and check if that block was air, if it is then make it grass otherwise dirt

the method above allows grass to grow under cliffs if you’re using 3d noise

another method is to make the y loop inside the x and z loop and before running the y loop have a variable that is set to true once it generates a block, that block will be grass (the y loop starts at height limit and goes downwards)

one that i do suggest doing over all of these is putting all your block results into a table (vector being the index and the blocktype being the value) and then checking if air (nothing) is above the block, change it to grass if that’s the case and then use that table to generate the blocks afterwards

that variable would be a boolean value?

yes every iteration in the y loop should check if there’s a block if there’s a block, check if that boolean is false, if it is then set it to true and make a grass block

This would look like this in pseudocode:

for x loop
 for z loop
  grass = false
  for y loop
   if not grass then 
    create grass
    grass = true

or should I put grass inside for loop?

that should be right as long as it’s inside the x and z but not y

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.