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

How would i go about making part-terrain without using 500k parts?

Asked by
nachsor 36
4 years ago

Hello,

Sorry to bother everyone, i was trying to post on the devforum but i still can't seem to be able to post there. Anyways, i am currently trying to make terrain generation for my game, the only issue... it has a looooooooooooooot of parts. I was wondering if there was a way to make it lag less? This is the script i have that generates the terrain.

noiseScale = 30 -- Smoothing (Default 30)
amplitude = 10 -- Height Fluctuation (Default 10)
blockSize = 4 -- Size of each block (Default 4)

maxXSize = 2048/blockSize
maxYSize = 64
maxZSize = 2048/blockSize
seed = math.randomseed(tick())
for x = -(maxXSize / 2), maxXSize do
    for z = -(maxZSize / 2), maxZSize do
        for y = 0, maxYSize do
            xNoise = math.noise(y/noiseScale, z/noiseScale, seed) * amplitude
            yNoise = math.noise(x/noiseScale, z/noiseScale, seed) * amplitude
            zNoise = math.noise(x/noiseScale, y/noiseScale, seed) * amplitude

            density = xNoise + yNoise + zNoise + y
            if density < 25 and density > 23 then
                parts = Instance.new("Part",game.Workspace.Terrain)
                parts.Anchored = true;
                parts.Size = Vector3.new(blockSize, blockSize, blockSize)
                parts.CFrame = CFrame.new(x * blockSize, y * blockSize, z * blockSize)
                parts.TopSurface = Enum.SurfaceType.Smooth
                parts.CastShadow = false
                parts.Massless = true
            end
        end
    end
    wait(0.3)
end

I have tried everything i can think of to make each part lag less but it has reached the point where it is not enough. With my current script, there should be around...524,288 parts(this is just an approximation, maybe there is 100k more for all i know...). Anyways, is there a way to use less parts or at least not make it lag as much.

Thank you! :D

0
Well... you could use the terrain editor and that creates less lag winner2807 30 — 4y
0
Also, you could store some larger objects, like unions that also randomly generate in-game sergeant_ranger 184 — 4y
0
Yes but how would i make different terrains everytime with the terrain editor? As for sergeant_ranger's suggestion, the size of the cubes is already right up the limit for how high the player can jump, making them bigger will stop the player from being able to do so, and i don't want to mess with the players jump height. Maybe i just misunderstood though! nachsor 36 — 4y
0
Try Using Bigger Parts Aartizx 0 — 4y
0
I have, it still causes large amounts of lag and impedes the players ability to move around the terrain. This is an issue because i don't want to mess with the player's character other than adding a shift sprint feature. Anyways i found a solution, simply using roblox terrain instead of parts. Found the neat little function's that allow you to make terrain by giving it a few values, works well! nachsor 36 — 4y

Answer this question