Help with terrain genaration system

Hello There! i am currently programming a voxel based terrain generation system to level up my current
programming level, but i have into into a roadblock.I am using 3D Perlin noise to make the terrain and it works great. But, the problem is that the noise function i made keeps on resetting itself after a chunk is generated, and make the chunk a carbon copy of the last chunk, just in a different position.My goal is to be able to generate a continuous smooth terrain, and being able to load chunks in and out, without it being a carbon copy of another chunk.


local C1 = game.Workspace:WaitForChild("Part1")
local C2 = game.Workspace:WaitForChild("Part2")
local Data = game:GetService("ServerStorage")
local DtaMod = require(Data.Modules:WaitForChild("DataModule"))
local ErrMod = require(Data.Modules:WaitForChild("ErrorModule"))
local frequency = 50
local ampllitude = 20
local avg = 0




local function Perlin(x,y,z,ChunkGenX,ChunkGenZ)
	
	local AB = math.noise(y/frequency,z/frequency,12345)*ampllitude
	local BC = math.noise(x/frequency,z/frequency,12345)*ampllitude
	local AC = math.noise(x/frequency,y/frequency,12345)*ampllitude
   

	avg =AB+BC+AC+y
	print(avg)
	return avg
	
end


local function CreateChunk(size,Cal,Cal2,Pos,ChunkNm,Cx,Cz)
		Cal2.Position = Cal.Position + Vector3.new(Pos,0,Pos)
	
		ErrMod.ChunkSettings(Cal,Cal2,size)

	
	local XZpos = math.floor(math.abs((((Cal.Position-Cal2.Position)/size).X)))
	
	local Ypos = DtaMod.ChunkSettings.ChunkHeight
	
	local ModPos = Cal.Position
	local ModPos2  = Cal2.Position 
	local Multx = 1
	local Multz = 1
	if ModPos.X>ModPos2.X then
		Multx = -1		

	end
	if ModPos.Z>ModPos2.Z then
		Multz = -1		
	end

	local Numnlk = 0	
	
	for Y1 = 1 , Ypos do
	
		for Z1 = 1, XZpos do 
			for X1=1,XZpos do
				local a = Perlin(X1,Y1,Z1,Cx,Cz)
				if a<15  then
				local block = Instance.new("Part")
				block.Size = Vector3.new(size,size,size)



				block.Position = Vector3.new(ModPos.X+((Multx*(((X1-1)*size)+size/2))),(ModPos.Y+((Y1-1)*(size)+size/2)),(ModPos.Z+(Multz*(((Z1-1)*size)+size/2))))
				block.Parent = game.Workspace
				
				block.Anchored = true
				Numnlk = Numnlk +1		
				block.Name = "block"..tostring(Numnlk).."/"..ChunkNm	
				end
							
				
			end
			
		end
		game:GetService("RunService").Heartbeat:Wait()
	end	
end



local function CreateChunkCluster() 
	local ChunkNum = 0

	local mu = DtaMod.ChunkSettings.RelativePosition
	local add  = 0
	for ZChunkAmount = 1,2 do
		for XChunkAmount = 1,2 do
			ChunkNum = ChunkNum+1
			CreateChunk(DtaMod.ChunkSettings.BlockSize,C1,C2,DtaMod.ChunkSettings.RelativePosition,ChunkNum,XChunkAmount,ZChunkAmount)
			C1.Position = Vector3.new((C1.Position.X+mu),0,add)	
			print("final"..avg)
		end
		add = add + mu
		C1.Position = Vector3.new(0,0,add)
		
	end
	
		
	

end

CreateChunkCluster()

here are some pictures of the problem

problem 2

please help if you can!

2 Likes

You are calling the noise function with the same X and Y for every cell. Instead, you should use the world coordinates of every cell and not its chunk coordinates.

2 Likes

what do you mean by the world coordinates of every cell? like, the global pos of every block?

Yeah, its actual position instead of its position within the chunk.

1 Like

but, how would I make that work? would i take the values from the block, and put it into the Perlin noise function?

I implemented it, AND IT WORKS!! THANK YOU SOO MUCH!

1 Like