Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Using Perlin Noise correctly with varying "seeds"?

Asked by 9 years ago

Basically I wish to use Perlin Noise, thanks to BlueTaslem, for terrain generation using bricks. Below is the script.

Since I'm not experienced with Perlin Noise, I decided to look into it a little, but didnt find much that I understood, nor how to use correctly. So any assistance with changing the values slighty and getting more "biomes" would be appreciated.

If you don't want to write code for me that's fine, I just want guided on the right path :)

local worldX = 100
local worldZ = 100
local blockWidth = 2
local blockHeight = 2

local model = Instance.new("Model")
model.Parent = game.Workspace
model.Name = "TerrainParts"

for _, obj in pairs(workspace.TerrainParts:GetChildren())do
    if obj:IsA("Part") and obj.Name == "TerrainBlock" then
        obj:Destroy()
    end
end

function height(x, y) -- The Spot That Uses Perlin Noise
    return (math.noise(x/20, y/20) + math.noise(x/35, y/35) + math.noise(x/77, y/77)) * 10 + 10
end

for x = 0, worldX, blockWidth do
    for z = 0, worldZ, blockWidth do
        local brick = Instance.new("Part")
        brick.FormFactor = "Custom"
        brick.Anchored = true
        brick.Size = Vector3.new(blockWidth, blockHeight, blockWidth)
        local y = math.random() + 4
        brick.Position = Vector3.new(x, height(x, z), z)
        brick.BrickColor = BrickColor.Green()
        brick.TopSurface = 0
        brick.Name = "TerrainBlock"
        brick.Parent = game.Workspace.TerrainParts
        wait()
    end
end

~ Legobuildermaster

1 answer

Log in to vote
0
Answered by 9 years ago
local worldX = 200
local worldZ = 200
local blockWidth = 2
local biomeRange = 50
local blockHeight = 2
local biomes = {}
biomes[0] = {"Bright yellow","Sand"}
biomes[1] = {"Bright green","Sand"}
biomes[2] = {"Camo","Sand"}
biomes[3] = {"White","Sand"}

local model = Instance.new("Model")
model.Parent = game.Workspace
model.Name = "TerrainParts"

for _, obj in pairs(workspace.TerrainParts:GetChildren())do
    if obj:IsA("Part") and obj.Name == "TerrainBlock" then
        obj:Destroy()
    end
end 

function biome(x,y) -- What biome this spot is
    print(math.abs(math.floor(math.noise(x/biomeRange,y/biomeRange)+.8))*#biomes)
    return biomes[math.abs(math.floor(math.noise(x/biomeRange,y/biomeRange)*#biomes+.5))]
end

function height(x, y) -- The Spot That Uses Perlin Noise
    return (math.noise(x/20, y/20) + math.noise(x/35, y/35) + math.noise(x/77, y/77)) * 10 + 10
end

for x = 0, worldX, blockWidth do
    for z = 0, worldZ, blockWidth do
    local partBiome = biome(x,z)
        local brick = Instance.new("Part")
        brick.FormFactor = "Custom"
        brick.Anchored = true
        brick.Size = Vector3.new(blockWidth, blockHeight, blockWidth)
        local y = math.random() + 4
        brick.Position = Vector3.new(x, height(x, z), z)
        brick.BrickColor = BrickColor.new(partBiome[1])
        brick.Material = partBiome[2]
        brick.TopSurface = 0
        brick.Name = "TerrainBlock"
        brick.Parent = game.Workspace.TerrainParts
    end
    wait()
end





I've not done much with biomes before, but I think this will work. I've made it so that you can easily add in/remove different biomes. If you wanna add in another biome, just add in another table inside the biome table, with the first value being the brick color, and the second one being the material. The actual use of the biome is very simple, and I hope will be easy for you to change, if needed. (as the biome selection I presume is more important)

Ad

Answer this question