Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use wedges to make perlin noise terrain smoother?

I have an script for my game and, to make it not look like I'm copying Minecraft, I planned on adding wedges. However with this script it just looks terrible. Anyone can help me?

Screenshot: Screenshot

Game as demo: (uncopylocked, hopefully): Demo game

math.randomseed(tick())

local size = 64
local seed = math.random(10, 1000) * os.time()
local scale = math.random(2, 8) / 100
local grass = game.ReplicatedStorage:WaitForChild("GrassBlock")
local dirt = game.ReplicatedStorage:WaitForChild("DirtBlock")
local wedges = game.ReplicatedStorage:WaitForChild("Wedges")
local blockSize = 4
local amplitude = 10

function getY(x, z)
	return math.noise(x * scale, z * scale, seed)
end

function drawTerrain()
	local blockSizeVector = Vector3.new(blockSize, blockSize, blockSize)
	
	for x = 1, size do
		for z = 1, size do
			local y = math.floor(getY(x, z) * amplitude)
			
			-- Extra wedges
			local xp = math.floor(getY(x + 1, z) * amplitude)
			local zp = math.floor(getY(x, z + 1) * amplitude)
			local xm = math.floor(getY(x - 1, z) * amplitude)
			local zm = math.floor(getY(x, z - 1) * amplitude)
			
			local addedWedge = false
			
			local wedge = nil
			
			if xp > 0 and xm <= 0 then
				wedge = wedges.xp1zp0xm0zm0
			elseif xp <= 0 and xm > 0 then
				wedge = wedges.xp0zp0xm1zm0
			end
			
			if wedge ~= nil then
				local objX = wedge:Clone()
				objX.Parent = game.Workspace
				objX.Position = Vector3.new(x * blockSize, y * blockSize, z * blockSize)
				objX.Size = blockSizeVector
				addedWedge = true
			end
			
			wedge = nil
			
			if zp > 0 and zm <= 0 then
				wedge = wedges.xp0zp1xm0zm0
			elseif zp <= 0 and zm > 0 then
				wedge = wedges.xp0zp0xm0zm1
			end
			
			if wedge ~= nil then
				local objZ = wedge:Clone()
				objZ.Parent = game.Workspace
				objZ.Position = Vector3.new(x * blockSize, y * blockSize, z * blockSize)
				objZ.Size = blockSizeVector
				addedWedge = true
			end
			
			-- Base terrain
			if addedWedge == false then
				local g_block = grass:clone()
				g_block.Parent = game.Workspace
				g_block.Position = Vector3.new(x * blockSize, y * blockSize, z * blockSize)
				g_block.Size = blockSizeVector
			end
			
			local d_block = dirt:clone()
			d_block.Parent = game.Workspace
			d_block.Position = Vector3.new(x * blockSize, (y - 1) * blockSize, z * blockSize)
			d_block.Size = blockSizeVector
		end
	end
end

drawTerrain()

(the wedge in that demo totally aren't called "halfblocks" because I forgot they were called wedges)

1 answer

✓ Accepted answer

I figured out it was because I was checking for as if the y axis was 0

1 comment

0

it b like that.... glad you got it working!

This discussion is preserved as it was. New answers, comments, and votes are closed.