Math.noise generated map chunks not lined up

1.i want to make a perlin noise map chunk generator

2.Chunks arent lined up

3.ive spent a lot of the past 24 hours trying to figure this out but nothing works ive looked on every dev forum i could find but nothing worked

local Storage = game.Workspace.PerlinNoiseStorage
local RunService = game:GetService("RunService")

local PartSize = 2
local ChunkSize = 16
local ChunkAmount = 2
local Resolution = 200
local Frequency = 7
local Amplitude = 50

local Chunks = {}

local Coroutines = {}
local CoroutinesCreated = 0

local rng = Random.new()
local DirtSeed = rng:NextInteger(-10e6, 10e6)

local function LoadChunk(ChunkX, ChunkZ, CoroutinesCreated)
	local printbool = false
	local Success, ErrMessage = pcall(function()
		local Blocks = Chunks[ChunkX][ChunkZ]
		for X, ValueX in pairs(Blocks) do
			for Z, ValueZ in pairs(ValueX) do
				for Y, ValueY in pairs(ValueZ) do
					local Part = Instance.new("Part")
					Part.Anchored = true
					Part.Size = Vector3.new(PartSize,PartSize,PartSize)
					Part.Position = Vector3.new(X, Y*Amplitude, Z)
					Part.Color = Color3.new((Y+0.5)/10, Y+0.5, (Y+0.5)/10)
					Part.Parent = Storage
					task.wait()
					if printbool == false then
						printbool = true
						print("ChunkX:", ChunkX, "ChunkZ:", ChunkZ)
						print("X:", X, "Y:", Y, "Z:", Z)
						print("Y:",Y, "Amplitude:", Amplitude, "Result:", Y*Amplitude)
						print("Part Position:", Part.Position)
					end
				end
			end
		end
		Coroutines[CoroutinesCreated].close()
	end)
end

for X = 1, ChunkAmount do
	Chunks[X] = {}
	for Z = 1, ChunkAmount do
		Chunks[X][Z] = {}
		local Blocks = Chunks[X][Z]
		local ExtraX = (X * ChunkSize * PartSize) + PartSize
		local ExtraZ = (Z * ChunkSize * PartSize) + PartSize
		for X = 1, ChunkSize do
				Blocks[ExtraX+(X*PartSize)] = {}
				for Z = 1, ChunkSize do
					Blocks[ExtraX+(X*PartSize)][ExtraZ+(Z*PartSize)] = {}
					local Y = math.clamp(math.noise((ExtraX+X)/Resolution*Frequency, (ExtraZ+Z)/Resolution*Frequency, DirtSeed), -0.5, 0.5)
					Blocks[ExtraX+(X*PartSize)][ExtraZ+(Z*PartSize)][Y] = "Part"
				end
			end
		task.wait()
	end
end

for X, XValue in pairs(Chunks) do
	for Z, ZValue in pairs(XValue) do
		local Success, ErrMessage = pcall(function()
			CoroutinesCreated +=1	
			warn("New Chunk Started")
			Coroutines[CoroutinesCreated] = coroutine.create(LoadChunk(X, Z, CoroutinesCreated))
			Coroutines[CoroutinesCreated].resume()
			task.wait()
		end)
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Check out his page:

It has an example which might help even though it is using terrain.

The math.noise function is continuous so something went wrong with the loops. What if the part size is 1?

This code is confusing me to be honest, but you just have to make sure you are adding chunk values to position like this:

Part.Position = Vector3.new(X, Y*Amplitude, Z)
-- into
Part.Position = Vector3.new(X+ChunkX*ChunkSize , Y*Amplitude, Z+ChunkZ*ChunkSize )

it turns out that math.noise must be used
in one loop to be most accurate cause it uses the last values or something in order to be similar so i gotta load the map and then load all the chunks in order for it to work

i did all that it was just added beforehand

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.