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

I made a terrain generator but for some reason there are random holes in the map sometimes?

Asked by 5 years ago

I have a terrain generator, and it generates terrain forever. But when it continues to generate terrain for some reason there are random holes in the map, why does it do this?

Here is the code:

local Part = game.ServerStorage:WaitForChild("GrassBlox") --For cloning
Part.Anchored = true
Part.FormFactor = "Custom"
Part.Size = Vector3.new(1, 2, 1)
local seed = math.random(1, 10e6)
local frequency = 2
local power = 10
local resolution = 100
local Iteration = 0

function GenMap(Offset1, Offset2)
for x = 1, resolution do
    wait()
    for z = 1, resolution do
        local y1 = math.noise(
            (x*frequency)/resolution,
            (z*frequency)/resolution,
            seed
        )

        local y2 = math.noise(
            (x*frequency*.125)/resolution,
            (z*frequency*.125)/resolution,
            seed
        )

        local y3 = math.noise(
            (x*frequency*4)/resolution,
            (z*frequency*4)/resolution,
            seed
        )

        local y = (y1*y2*power*power)+y3

        local Part = Part:Clone()
        Part.Parent = game.Workspace
        Part.CFrame = CFrame.new(x + Offset1, math.floor(y + 0.5), z + Offset2)

        end
    end
end

while true do
    if not frequency == 2 and not frequency == 0 then
    frequency = math.random(frequency - 1, frequency + 1)
    elseif frequency == 0 then
    frequency = frequency + 1
    elseif frequency == 2 then
        frequency = frequency - 1
    end

    if not power == 2 and not power == 10 then
    power = math.random(power - 1, power + 1)
    elseif power == 2 then
    power = power + 1
    elseif power == 10 then
        power = power - 1
    end

    Iteration = Iteration + resolution
    GenMap(Iteration, 0)
    seed = math.random(seed - 1, seed + 1)
    wait(10)
end

0
I'm not really sure the ROBLOX implementation of perlin noise is meant to be used like this. Maybe I'm wrong, but what seems to be happening is that the pattern is repeating. When you have a high at the start of the pattern and a low at the end, a gap is generated. fredfishy 833 — 5y
0
Also your logic in the while loop is really messy. Something like this is slightly more readable: https://i.imgur.com/UqbQcxF.png fredfishy 833 — 5y
0
Also, while I doubt this is the issue, `power` isn't used as a power. You're squaring it and multiplying by the result. fredfishy 833 — 5y
0
Basically it's hard to work out what's going wrong because (A) ROBLOX's documentation for perlin noise is poor (B) your code isn't particularly clear fredfishy 833 — 5y
View all comments (2 more)
0
There was an almost identical question as this a few days ago, maybe you can look at the code in that terrain generator to help you solve your problem? SteamG00B 1633 — 5y
0
I guess ... DragRacer31 7 — 5y

Answer this question