Using Perlin Noise To Make A Map

I will try to explain how I made my first map using Perlin Noise.

(I am not a professional at this)

Making the map:

local Part = Instance.new("Part") --For cloning
Part.Anchored = true
Part.FormFactor = "Custom"
Part.Size = Vector3.new(4,4,4)
Part.TopSurface = "Smooth"    

local seed = math.random(1, 10e6)
local frequency = 3
local power = 4
local resolution = 100 

for x = 1, resolution do  
	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.Map
        Part.CFrame = CFrame.new(x,y,z)
		
		--[[if math.abs(y2) < .1 then
		    Part.BrickColor = BrickColor.Green()
		elseif math.abs(y2) > .25 then
		    Part.BrickColor = BrickColor.Red()
		else
			Part.BrickColor = BrickColor.Blue()
		end]]
		
	end
end

This code makes a basic map.

local Part = Instance.new("Part") --For cloning
Part.Anchored = true
Part.FormFactor = "Custom"
Part.Size = Vector3.new(4,4,4)
Part.TopSurface = "Smooth"    

This is the part of the code that creates a part.

local seed = math.random(1, 10e6)
local frequency = 3
local power = 4
local resolution = 100 

This part is important, the values make the map. Try changing the values. Changing the values will help you understand what those Values do.
the Seed: The seed is kinda the name of the map. If you change the seed you will get a different map.
the Frequency: The frequency, you should keep the frequency low to get smoother terrain.
the Power: if you want higher Terrain you should make the Power a high number but if you want smoother terrain you should keep it low.
the Resolution the Resolution is basically the size of the map. The bigger the number the bigger the map will be (Idk if that sentence made sense) (if you make the resolution bigger the map gets bigger).

 for x = 1, resolution do  
    	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.Map
        Part.CFrame = CFrame.new(x,y,z)
		
		--[[if math.abs(y2) < .1 then
		    Part.BrickColor = BrickColor.Green()
		elseif math.abs(y2) > .25 then
		    Part.BrickColor = BrickColor.Red()
		else
			Part.BrickColor = BrickColor.Blue()
		end]]
		
	end
end

This is the part that makes the map. You should change the

 for x = 1, resolution do  
        for z = 1, resolution do

to get the map you want.
just experiment with the numbers until you get the map style you like. I will edit this post or I will make other posts to show you guys how you can add trees, water to your map if you know some stuff about Perlin Noise please reply to this post so that other people can learn too.

Edit:
How to add water?
Many people use a code to add water to their maps but I used the terrain editor.
terrainEditor
I used the Sea Level to add water.
I suggest you keep your sea level below 1 or 0. But if you want water to be high make the sea level higher. Using sea level is easier than coding it.

19 Likes

Great tutorial! I’m going to keep this saved for later use.

1 Like

Thank you! Hope this tutorial helps.

do we put this in a local script or a script? Where do we put it?

Put it in a script in Workspace

Really nice tutorial! I’m gonna try it right now in studio!

1 Like

Great tutorial, but what if we (myself) don’t know what Perlin Noise is? Is it like a noise texture in blender?

1 Like

Perlin Noise is used for making maps. It always creates a random map because of its values math.noise(X,Y,Seed) the seed is always different that’s why it always creates a different map.
for more information you can take a look at this tutorial: Basics of using Perlin Noise (2D Based)

2 Likes

Hey, just a heads up, you should change Part.CFrame = CFrame.new(x,y,z) to Part.CFrame = CFrame.new(x * 4, y * 4, z * 4), because right now the map parts are overlapping by 3 studs each. Your map will be 4x larger with no performance drawbacks and the parts would not be overlapping.

4 Likes

Thank you tried it. But it breaks the trees I will have to fix that. But that is awesome thank you.

1 Like

Also, I made a few edits to your code & fixed a few things, and here is the result:

Result

https://www.roblox.com/games/4486830141/Demo?refPageId=ddabb2ca-8308-441f-9731-e798e9d125e9

Unfortunately my pc is pretty awful, so I can’t take a video to show the map as well as I wish to. I published the game to roblox (link in “Result” section), so if anyone wants to take a video and post it here, I will be greatful :smiley: . (Note, it looks best on high graphics, so be sure to turn your graphics as high as possible for the best result :slight_smile: )

1 Like

It looks awesome what did you change? or did you add something?

I changed threes to have leaves and made them random shades of green. I also lowered the water to prevent overflow, which I saw in your version. Then I added some bloom, blur, sun rays and colour correction. Finally I made the camera a free camera instead of being limited to the character. There were a few other minor changes, but they don’t matter that much. I’m not going to make the project open source because the code isn’t really anything worthy of viewing; I just scrapped it together in a matter of minutes.

1 Like

Looks good!

I will try it later.

1 Like

How would I go about layering the perlin noise to make it more realistic?.

Thanks.