Level of detail system doesn't scale chunks

My chunk system doesn’t scale chunks properly so the lower detail chunks stay the same size as higher detail chunks. I tried solving this but theres no solutions I could find/work out.

Screenshot

Script

local OceanMeshes = game.Workspace.OceanMeshes

local Size = 10

local MaxVertices = 10

-- Other Settings

local Level = 10

local Grid = Size * MaxVertices - MaxVertices

local chunks = {}

local function createchunk(xpos, zpos, iteration)
	local mesh = Instance.new("MeshPart")
	mesh.Parent = OceanMeshes
	mesh.Position = Vector3.new(math.round(xpos / Grid)*Grid, Level, math.round(zpos / Grid)*Grid)
	mesh.Size = Vector3.new(1,1,1)
	mesh.Anchored = true
	mesh.CanCollide = false
	mesh.CastShadow = false
	mesh.Name = "Iteration" .. iteration
	
	table.insert(chunks, mesh)
	
	local Vertices = math.ceil(MaxVertices / iteration)
	Vertices = math.max(Vertices, 2)
	
	local Width = Vertices
	local Height = Vertices
	
	local Offset = Size

	
	local editableMesh = Instance.new("EditableMesh")
	editableMesh.Parent = mesh
	
	local Vertices = {}

	for y = 1, Height do
		local raw = {}
		for x = 1, Width do
			local vertexPosition = Vector3.new(x - 1 - (Width / 2), 0, y - 1 - (Height / 2)) * Offset
			local vertexId = editableMesh:AddVertex(vertexPosition)

			raw[x] = {vertexId, vertexPosition}
		end
		Vertices[y] = raw
	end

	for y = 1, Height-1 do
		for x = 1, Width-1 do
			local vertex1 = Vertices[y][x][1] :: number
			local vertex2 = Vertices[y+1][x][1] :: number
			local vertex3 = Vertices[y][x+1][1] :: number
			local vertex4 = Vertices[y+1][x+1][1] :: number

			local triangle1 = editableMesh:AddTriangle(vertex1, vertex2, vertex3)
			local triangle2  = editableMesh:AddTriangle(vertex2, vertex4, vertex3)
		end
	end
end

The triangles always stay the same size, but I need them to change sizes depending on how many triangles are per chunk. If theres another way I could size chunks more optimally, let me know.

Any help is appreciated!

3 Likes

Update: Fixed it by using less level of detail values, taking the grid and plugging it into size for the low detail chunks

1 Like

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