Replicating Studio panning camera behavior

I had an idea to make a spawn location selection screen in 3D.
How I thought it would work is like the middle-click function in studio. Here is how to get my desired effect:

  1. Select the Top face of the view selector
  2. Press and hold the scrollwheel
  3. Move your mouse around

Your camera will move around proportional to the mouse, and keep looking down. This is what I wanted to do in my game.

How would I do something like this?
I know this would have something to do with mouse.Position, but I dont really know how to calculate the new camera position.

I also tried getting the code from the Studio files, but I couldnt find anything. Is it actually possible to fork the default studio camera?

Help would be appreciated!

Any solutions?
This is what I got so far:

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local mouse = plr:GetMouse()
local oldX = 0
local oldY = 0
local x = 0
local y = 0
local pressed = false

spawn(function()
while true do
	cam.CameraType = Enum.CameraType.Scriptable
		
	local moveX = (oldX - x)/5
	local moveY = -((oldY - y)/5)
		
		cam.CFrame = CFrame.new(Vector3.new(moveY, 60, moveX), Vector3.new(moveY,0,moveX))
	wait()
	end
end)

mouse.Move:Connect(function()
	if pressed then
		x = mouse.X
		y = mouse.Y
	end
end)

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton3 then
		pressed = true
		oldX = mouse.X
		oldY = mouse.Y
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton3 then
		pressed = false

	end
end)

Almost works, it just resets back to 0 when you click again

With some help from the DevForum, I finally got it!
If you are interested, here you go!

local camera = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local mouse = plr:GetMouse()
local x = 0
local y = 0
local pressed = false

wait(3)
camera.CameraType = Enum.CameraType.Scriptable
wait(1)
camera.CFrame = workspace.Cam.CFrame

mouse.Move:Connect(function()
	if pressed then
		local moveX = x - mouse.X
		local moveY = y - mouse.Y
		
		camera.CFrame = camera.CFrame + 
			(camera.CFrame.RightVector * moveX)/10 +
			(camera.CFrame.UpVector * -moveY)/10
		
		x = mouse.X
		y = mouse.Y
	end
end)

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		pressed = true
		x = mouse.X
		y = mouse.Y
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		pressed = false
	end
end)

For it to work, you need a part in workspace named “Cam” with orientation -90, -180, 0