How to use Perlin Worms?

I have a Perlin Noise code. But I also want to add caves. I found out that for the caves we need to use something called Perlin worms. I have a code for it too but it doesn’t work as I want it to here is the code:

local Seed = tick()

print("Seed is: "..Seed)

local Resolution = 4

local NumWorm = 1

while wait() do

NumWorm = NumWorm+1

local sX = math.noise(NumWorm/Resolution+.1,Seed)

local sY = math.noise(NumWorm/Resolution+sX+.1,Seed)

local sZ = math.noise(NumWorm/Resolution+sY+.1,Seed)

local WormCF = CFrame.new(sX*500,sY*500,sZ*500)

print("Worm "..NumWorm.." spawning at "..WormCF.X..", "..WormCF.Y..", "..WormCF.Z)

local Dist = (math.noise(NumWorm/Resolution+WormCF.p.magnitude,Seed)+.5)*500

for i = 1,Dist do

wait()

local X,Y,Z = math.noise(WormCF.X/Resolution+.1,Seed),math.noise(WormCF.Y/Resolution+.1,Seed),math.noise(WormCF.Z/Resolution+.1,Seed)

WormCF = WormCF*CFrame.Angles(X*2,Y*2,Z*2)*CFrame.new(0,0,-Resolution)

workspace.Terrain:FillBall(WormCF.p,Resolution,Enum.Material.Grass)

end

end

but this code doesn’t make caves. How can I make it make caves?

2 Likes

Please be more specific on what is not working and what is, the documentation of the source code would be highly appreciated, so we can know what a specific line of code does. The thing you described at the bottom sounds like cloning the model inside workspace but I am at the same time not sure because it’s not clear enough inside a thread for me. Thank you.

The code is working fine but it isn’t placing parts it’s placing dirt (the grass from the terrain editor) and I need it to be placing parts so that I can make those parts Cancollide false and transparancy 1 so that it makes a cave.

if you need more information just reply.

I am still kind of confused because I think what you need is not possible but you might try :FillBlock() function which creates a block terrain instead of ball as you have in the script. You can define in which position the terrain should be made like this for example:

game.Workspace.Terrain:FillBlock(game.Workspace.Part.CFrame, game.Workspace.Part.Size, Enum.Material.Grass)

image

this is what the code does (not your code my code)

but I need it to make it from parts instead of grass blocks.

You mean like this?

local Seed = tick()
print("Seed is: "..Seed)
local Resolution = 4
local NumWorm = 1

while wait() do
	NumWorm = NumWorm+1
	local sX = math.noise(NumWorm/Resolution+.1,Seed)
	local sY = math.noise(NumWorm/Resolution+sX+.1,Seed)
	local sZ = math.noise(NumWorm/Resolution+sY+.1,Seed)
	local WormCF = CFrame.new(sX*500,sY*500,sZ*500)
	print("Worm "..NumWorm.." spawning at "..WormCF.X..", "..WormCF.Y..", "..WormCF.Z)
	local Dist = (math.noise(NumWorm/Resolution+WormCF.p.magnitude,Seed)+.5)*500

	for i = 1,Dist do
		wait()
		local X,Y,Z = math.noise(WormCF.X/Resolution+.1,Seed),math.noise(WormCF.Y/Resolution+.1,Seed),math.noise(WormCF.Z/Resolution+.1,Seed)
		WormCF = WormCF*CFrame.Angles(X*2,Y*2,Z*2)*CFrame.new(0,0,-Resolution)
		local Part = Instance.new("Part")
		Part.Anchored = true
		Part.CFrame = CFrame.new(WormCF.p)
		Part.Parent = workspace
	end
end
10 Likes

Yes, That is what I mean.

print("Yes")

Okay, I just updated the reply.

Yeeey, It worked ty.

print("Thank You")

how to use it to make caves???

When a new position is generated, check if there is a part there, and delete it. You can delete surrounding parts too if you want.

Can 2D perlin worms be used to make Rivers that meander within the Terrain?