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

Does anyone know why I just get a plain baseplate when using math.noise for the Y position?

Asked by 6 years ago
Edited 6 years ago

So, basically I'm trying to do a "Custom Terrain" with math.noise. The next script generates a new series of parts, which uses math.noise to set the part's Y position, but for some reason every part has roughly the same Y position..? There's no parts nor models inside Workspace.

Server Script located in Workspace:

local function NewCells()
    for line = -X, X, 1 do
        for collumn = -Z, Z, 1 do
            local Cell = Instance.new("Part", workspace.Cells)
            Cell.Anchored = true
            Cell.Size = Vector3.new(Size, Size, Size)
            local Y = MinY + (MaxY - MinY) * (1 + math.noise(MinY / Size, MaxY / Size, Seed) / 2)
            Cell.Position = Vector3.new(line, Y, collumn)
        end
    end
    Seed = math.random(0, 1000)
end

while true do
    if #workspace.Cells:GetChildren() <= 0 then
        NewCells()
    else
        workspace.Cells:ClearAllChildren()
        NewCells()
    end
    wait(5)
end

Hope someone helps me figure this out. Thanks.

1 answer

Log in to vote
0
Answered by 6 years ago

The issue is that you used integers for both x, y and the seed. math.noise "If x, y and z are all integers, the return value will be 0"

Additional information on how to use math.noise can be found here

A quick example:-

local seed = math.random(0, 1000) + wait() -- create double

local x, z = 100, 100
local size = 0.1
local minY, maxY = 0, 5

local function NewCells()
    local cell = Instance.new('Part')
    cell.Anchored = true    
    cell.Size = Vector3.new(size, size, size)

    for i=0, x, size do
        for i2=0, z, size do
            local tmp = cell:Clone()
            tmp.Position = Vector3.new(i, minY + (maxY - minY) * (1 + math.noise(i, i2, seed) /2), i2)
            tmp.Parent = workspace
        end
        wait(1)
    end
end

NewCells()

I hope this helps.

Ad

Answer this question