Generating a mountain with math

I am trying to generate a mountain using math (simply) but it is turning into a tarpaulin more than a mountain code

for Number = -50, 50 do
	for Number2 = -50, 50 do
		local Y = Number * -Number / 25 + Number2 * -Number2 / 25 + 200
		local Part = Instance.new("Part")
		Part.CFrame = CFrame.new(Number * 5, Y, Number2 * 5)
		Part.Anchored = true
		Part.Size = Vector3.new(5, 5, 5)
		Part.Parent = workspace.Terrain
	end
end

I’d suggest using Perlin Noise instead of local Y = Number * -Number / 25 + Number2 * -Number2 / 25 + 200. ThinMatrix has made terrain with Perlin Noise before, this is what it looked like:

In my opinion this is a pretty good tutorial on how to generate procedural 3D terrain. Even though that tutorial is for Java, it can be translated to Lua for use in Roblox.

I dont want it to be random I want it to be linear

I’m not understanding what you mean with a linear mountain, could you show me an example please?

Use math.noise(x, y, seed).
Make sure that none of the parameters are integers.

They already mentioned they don’t want to use noise in an earlier reply.

Why is that important?

If all of the parameters are integers, you will get the same map every time (even if you change the seed).

Try this. The only change I made was calculating “Y”, you only want the first for loop to be for the y axis, and the second for loop to be for the X and Z axis.

for Number = -50, 50 do
	for Number2 = -50, 50 do
		local Y = Number2 * -Number2 / 12.5 + 200
		local Part = Instance.new("Part")
		Part.CFrame = CFrame.new(Number * 5, Y, Number2 * 5)
		Part.Anchored = true
		Part.Size = Vector3.new(5, 5, 5)
		Part.Parent = workspace.Terrain
	end
end

Nope that just builds and arch instead of what I have already got

Generating a mountain with math

How about this:

local MAXHEIGHT = 100
local RANGE = 50
local MAXRANGE = math.sqrt(2*range^2)

local dist, percentage
for x = -RANGE, RANGE do
	for z = -RANGE, RANGE do
		dist = math.sqrt(x^2+z^2)
		percentage = dist/MAXRANGE
		--here you could just do: y = (1 - percentage) * MAXHEIGHT
		--But lets smoothen the curve abit
		y = (1 + math.cos(percentage * math.pi)) * .5  * MAXHEIGHT
	end
end
1 Like

That works perfectly!! Here is a picture of how it turned out (I changed some numbers around)

1 Like