Random World Infinite Generation Script Ideas

Hello! I am currently trying to script an infinitely generating map, just I don’t know how I would be able to make it so it is able to just generate random hills, terrain, etc. in a 3x3x3 grid size. I have seen that this is possible on roblox, but I am not sure how to do it. I was wondering if anyone would be able to give “script ideas” (I am not asking for a whole script or anything) but just how the script could function so I can get an idea of how I could make it. Thanks for reading :slight_smile:

1 Like

Are you trying to make it using terrain or parts?

I am trying to make it by using blocks.

I have a few methods in mind for making a map like that, I’ve never put them into practice but theoretically it should work. Basically create a part of any size and put it into a script. Then you just need to script it so the first part clones and goes around Vector3(0, 0, 0) , you might want to name it something like Chunk1. You can clone the next part and have it be on the previous parts CFrame but slightly different. I will create a new Thread with steps and script. I will link it here in about 30 minutes or so after I make a script.

1 Like

Okay, thank you! (I hope this isn’t too hard for you to make)

Iv got a random design done, Im just making a more cleaner one,

Oh, sorry for forgetting to tell you, the blocks are always 3x3 and will always be placed in a “Grid” fashion, my fault :grimacing:

Yh, I figured, its an easy fix I just need a separate thread to work on -X, X ,-Z and Z axis

Oh, okay! Thought that would have messed it up, sorry for forgetting to tell you before :sweat_smile:

I can see why you had trouble with this. I can’t think of any clean ways to script this, so it may be messy in terms of the code.

1 Like

https://gyazo.com/7d6b278436163388f8287035ec476b34 This is basically what you want to do but faster.

1 Like

A common approach is to use coherent noise of some kind. Roblox has a built-in function called math.noise which generates a kind of coherent noise called Perlin noise.

Noise is essentially just “random outputs”, and coherent noise is noise where a small change of the input results in a small change in the output, while a large change in input makes a change in output that looks like white noise (just plain random).

We can use this property of coherent noise to generate smooth hills, by generating a heightmap where each (x, z) coordinate has an associated y value (height). The height in smooth hills varies smoothly and the change in height when you move just a small distance is low, so coherent noise is perfect for this. Large changes in height would be more like steep cliffs.

To turn a heightmap into a 3D block world, you can go through each (x, z) coordinate and place blocks from the bottom of the world and up until you reach the y value generated by the height map. This doesn’t make sense with negative height, so we add some baseheight to the generated height.

math.noise takes 1-3 inputs (x, y, z coordinates) and spits out a single number and behaves like described earlier. A “large change” in this case is a change of 1 or more in any of the coordinate components, so blocks that are next to each other should have almost the same input values to math.noise. We can do that by dividing their coordinate by a large-ish number. math.noise outputs numbers that are mostly in the range (-0.5; 0.5), but we want the height of the terrain to vary by more that 1 block, so we multiply the output by a large-ish number.

E.g.

local block = script.Block
local blockSize = block.Size
local worldSize = 64

--these terms come from things like sine waves
local frequency = 1/16
local amplitude = 8

local baseHeight = 1+ amplitude/2

for x = 1, worldSize do
    for z = 1, worldSize do
        local height = baseHeight + math.noise(
            x * frequency, 
            0,
            z * frewuency
        ) * amplitude
        for y = 1, math.floor(height) do
            local b = block:Clone()
            b.Position = Vector3.new(x, y, z) * blockSize
            b.Parent = game.Workspace
        end
    end
end

This approach has some limitations such as not being able to generate overhangs, so youll probably want to move to some more advanced techniques sooner or later. But its a good introduction to procedural terrain generation and how to use noise for that purpose.

Play around with the frquency and amplitude to see how they affect the terrain. If you want different terrain each time, add a (large, greater than the world size) seed number to any of the input coordinates to the noise func.

Let me know if you have questions :slight_smile:

You can read much more here: libnoise: Glossary

1 Like

To make this infinite, you need to generate terrainin a radius around the player, and then destroy generated terrain when the player gets too far away.

Your approach is definitely better that anything I can think off, mine was just made to create some plain land.

1 Like

Wow, thank you for the info! Very complicated to understand, but could possibly work!

1 Like

Wow! This really worked well! Thank you for helping!

1 Like

image
Was able to make this too with the method!

1 Like

Looks really good, like the materials :slight_smile: :+1:

Edit: you should probably cross- link between this post and the other one, because the info in both is useful for anyone else looking for help

1 Like