I designed a terrain generator that is supposed to randomly generate hills. However instead of hills, it sort of makes a... mashed-sideways lump. Here's the code:

--Created by XanthicDragon


Model = Instance.new("Model", workspace)

function Dome(x, dir, offset, h)
	local e = offset.X
	local r = offset.Y
	local m = offset.Z
	for y = -x, x do
		local m = y*y
		p = Instance.new("Part")
		p.FormFactor = "Custom"
		p.Size = Vector3.new(4, 4, 4)
		if dir == 1 then
			p.CFrame = CFrame.new(0+e, (-m/4-h)+r, y+m)
		elseif dir == 2 then
			p.CFrame = CFrame.new(y+e, (-m/4-h)+r, 0+m)
		elseif dir == 3 then
			p.CFrame = CFrame.new(y+e, (-m/4-h)+r, y+m)
		elseif dir == 4 then
			p.CFrame = CFrame.new(-y+e, (-m/4-h)+r, -y+m)
		elseif dir == 5 then
			p.CFrame = CFrame.new(y+e, (-m/4-h)+r, -y+m)
		elseif dir == 6 then
			p.CFrame = CFrame.new(-y+e, (-m/4-h)+r, y+m)
		end
		p.Anchored = true
		p.Parent = Model
	end
end

function Rand(o, h)
	for i = 1, 2 do
		for j = 1, 2 do
			Dome(i*j, 1, o, h)
			Dome(i*j, 2, o, h)
			Dome(i*j, 3, o, h)
			Dome(i*j, 4, o, h)
			Dome(i*j, 5, o, h)
			Dome(i*j, 6, o, h)
		end
	end
end

CURRENTPOS = nil
t = 4
for q = -t, t do
for w = -t, t do
	p = Instance.new("Part")
	p.FormFactor = "Custom"
	p.Size = Vector3.new(4, 4, 4)
	p.Anchored = true
	p.CFrame = CFrame.new(q*4, 0, w*4)
	p.Parent = Model
	CURRENTPOS = p.CFrame.p
end
local hill = math.random(1, 20)
local h = math.random(2, 4)
if hill <= 5 then
	Rand(CURRENTPOS, Vector3.new(h))
end
end

NOTE: Using only Rand() will create a hill!

1 comment

0

EXTRA: This was designed to create that superflat thing from Minecraft and add hills.