How to make a camera pan from the middle of the to a certain point left to right?

hey all, I am trying to figure out how to make it so when your mouse goes to one side of the screen, it moves the camera until a certain point. and, at the end of the movement, it snaps. how can i make it more smooth?

local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = game.Workspace.CurrentCamera

cam.CameraType = "Scriptable"

local camCF = workspace.gamer.CFrame
local angle = 0
local savedCF = camCF

RunService.RenderStepped:Connect(function()
    local center = Vector2.new(cam.ViewportSize.X / 2, cam.ViewportSize.Y / 2)
    local rotVector = Vector3.new(((mouse.X - center.X) / 150), (mouse.Y - center.Y) / 150, 0)
	
    if mouse.X < 250 and angle > -100 then
        print("panning left")
        angle = angle - 3
        
        cam.CFrame = savedCF * CFrame.Angles(0, math.rad(math.cos(cam.CFrame.Y + (angle / 750))), 0)	
        savedCF = cam.CFrame
        wait(0.1)
    elseif mouse.X > 1750 and angle < 100 then
        print("panning right")
        angle = angle + 3
        
		cam.CFrame = savedCF * CFrame.Angles(0, -math.rad(math.cos(cam.CFrame.Y + (angle / 750))), 0)
        savedCF = cam.CFrame
        wait(0.1)
    else
        cam.CFrame = savedCF * CFrame.Angles(math.atan(math.rad(-rotVector.Y)), math.atan(math.rad(-rotVector.X)), rotVector.Z)    
    end
end)

you may find this post i made a while ago helpful:

1 Like

i think you meant camera.CFrame.p for the first two arguments of portion, little correction, but the camera starts spinning wildly when implemented with my script. on its own it doesnt seem to work.

lol i didnt even notice that, that is pretty old code
try testing it now and tell me how it works, i fixed it