How do I remove this "smoothness" from this script?

I found a script that lets you pan the camera from a top down, Top Down Camera Pan [Open Source] - #4 by KUW_Alt1, but I had to make it work horizontally. But for some reason it’s a little “smooth”. I thought it was the lag of the tiles but it isn’t.


If I let go of the pan button, then it abruptly stops. I want the entire panning thing to but non-smooth.

Code:

local runService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")

local dragging = false
local PAN_SPEED = 10
local lastDragPosition

camera.CFrame = CFrame.new(Vector3.new(0,0,-50)) * CFrame.Angles(0,math.rad(180),0)
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 50

runService.RenderStepped:Connect(function(dt)
	if dragging then
		local delta = Vector3.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,0) - lastDragPosition
		camera.CFrame = CFrame.new(camera.CFrame.Position + -delta * dt * PAN_SPEED) * CFrame.Angles(0,math.rad(180),0)
	end
end)

uis.InputBegan:Connect(function(input,gpe)
	if input.UserInputType == Enum.UserInputType.MouseButton3 then
		dragging = true
		lastDragPosition = Vector3.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,0)
	end
end)

uis.InputEnded:Connect(function(input,gpe)
	if input.UserInputType == Enum.UserInputType.MouseButton3 then
		dragging = false
	end
end)

If you move the camera every frame, it will logically end up being smooth. A simple debounce will probably fix the “problem”. But honestly, why would you want it to be jagged instead of nice and smooth? Anyway, the code is something like this:

local debounce = true

runService.RenderStepped:Connect(function(dt)
  if dragging and debounce then
    local delta = Vector3.new(mouse.Hit.Position.X,mouse.Hit.Position.Y,0) - lastDragPosition
    camera.CFrame = CFrame.new(camera.CFrame.Position + -delta * dt * PAN_SPEED) * CFrame.Angles(0,math.rad(180),0)

    debounce = false
    task.wait(0.02)
    debounce = true
  end
end)

task.wait(0.02) will slow down the camera, so try increasing PAN_SPEED to compensate.

This is what the debounce did lol but thanks

Good point, do you know how I can make it smooth when I stop dragging, instead of it instantly stopping?

Maybe I’m just dumb, but that seems complicated seeing as you don’t know when the client will stop dragging. The simplest thing to do is to play a tween in the dragging direction when the client stops dragging, but that would make the camera a little inaccurate since you’re moving it even though the client isn’t dragging it anymore.