Minimap chunk to chunk transition feels weird

i made a phone minimap, and i followed a youtube tutorial which uses a chunk based map and i followed every step but for some reason, the chunk transition feels weird, even though the offset and chunkSize is formulated.

Minimap - Roblox Scripting Tutorial (i finished off at 19~ min)

External Media

as you can see, in the phone ui, everytime the chunk jumps one to another, it doesn’t feel smooth, and sometimes parts can disappear and appear everytime it jumps.

I think it has something to do with the ui’s size not being a square, but i tried changing it to 500x500 and 700x700, but it just makes it worse.

This is my code:

local frame = script.Parent
local camera = workspace.CurrentCamera

local viewportFrame = frame.ViewportFrame

for _, descendant in pairs(workspace.Map:GetDescendants()) do
	if descendant:IsA("BasePart") == false then continue end
	local clone = descendant:Clone()
	clone.Parent = viewportFrame
end

local viewportCamera = Instance.new("Camera")
viewportCamera.FieldOfView = 20
viewportFrame.CurrentCamera = viewportCamera

local offset = Vector3.new(0,750,0)
local chunkSize = offset.Y * math.tan(math.rad(viewportCamera.FieldOfView) / 2)
local chunkHalfSize = chunkSize / 2
local currentX, currentZ = math.huge, math.huge 

camera:GetPropertyChangedSignal("Focus"):Connect(function()
	local cx = camera.Focus.Position.X / chunkSize
	local cz = camera.Focus.Position.Z / chunkSize
	
	local chunkX = math.floor(cx)
	local chunkZ = math.floor(cz)
	
	local x = cx % 1
	local z = cz % 1
	
	if currentX ~=  chunkX or currentZ ~= chunkZ then
		currentX, currentZ = chunkX, chunkZ
		local position = Vector3.new(chunkX * chunkSize + chunkHalfSize, 0, chunkZ * chunkSize + chunkHalfSize)
		viewportCamera.CFrame = CFrame.lookAt(position + offset, position, -Vector3.zAxis)
	end
	
	viewportFrame.Position = UDim2.new(1-x, 0,1-z, 0)
	
end)

I need help please. thank you.

7 Likes

I suggest looking at your code again to see if it matches the videos. Sometimes, you can be off by one symbol. Also, take a look at the UI properties and see if it matches.

This is pure speculation since you didn’t share any code. There is likely something wrong with the modulus part of your code (the % operation) or the tangent calculations (math.tan). Those can cause snapping like that.

im very sorry for the lack of information, i forgot to add the code

Thanks for the info btw