Advice on draggable camera w/ inertia

Hi, so for a camera that is draggable/swipe-able along only one axis (no rotation) I’ve put this together.

With how I’ve done it, the camera movement stops immediately after the mouse button is lifted, I don’t want this. In an attempt to add some ‘inertia’ to keep moving the camera after a strong swipe I’ve added a tween when the mouse is lifted. The results are decent, but not perfect.

Currently, the camera sort of just follows the mouse, and holding it still at the side lets the camera drift. How would I make the camera movement more like its being dragged by the mouse being held down?

camera localscript

local R = game:GetService("RunService")

local cam = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")

local MouseOriginal
local Mouse2
local Mouse3
local Buttondown
local Movement 


local TS = game:GetService("TweenService")
local Style = Enum.EasingStyle.Cubic

function pan()
	Mouse2 = mouse.X
	local Distance1 = MouseOriginal-Mouse2 
	Movement = Distance1/500 --random number, dunno how to make the mouse distance into a reasonable X value.

	cam.CFrame = cam.CFrame + Vector3.new(Movement,0,0)
end

mouse.Button1Down:Connect(function()
	Buttondown = true	
	MouseOriginal = mouse.X	
end)

mouse.Button1Up:Connect(function()
	Buttondown = false
	Mouse3 = mouse.X
	local Distance2 = Mouse2 - Mouse3

	local TI = TweenInfo.new(1,Style)
	local Goal = {CFrame = cam.CFrame + Vector3.new(Distance2*2,0,0)} -- another random manipulation of the mouse distance that gave a reasonable movement.

	local Tween = TS:Create(cam,TI,Goal)
	Tween:Play()	-- Tween attempts to create swipe "inertia" after letting go, remove to just have the camera stop immediately after mouse up

end)


R.RenderStepped:Connect(function()
	cam.CameraType = "Scriptable"
	if Buttondown then
		pan()
	end
end)

Please advice if there is a better way to do this, I’m completely new to UIS and screensize stuff. Cheers!

Question are you trying to make the player screen turn faster? if so you can do that without scripts there should be an file for that like locking emotes/shiftlock mouse?

I don’t think I understand what you mean. I would like to lock the camera to a certain position, and only allow the player to pan it on only one axis by dragging.

So you want players to be in first person?

Could have it like that, but would be more practical if the camera is just locked to the location instead of on their body. Don’t have to move the bodies around into the perfect position to have the view needed.

Well I don’t get it what your talking about now, Sorry are you trying to make first person or players that cant zoom out far away, If so you don’t need a code for it, Like disabled emotes or shift lock there should be a section for zoom not sure sorry. To make players to not zoom out far away there should be an button top left corner for it in roblox studio and click setting for the game it’s in the section where you pick players r15 or r6 package or player choice section…