Top Down Camera Pan [Open Source]

This guy in scripting support needed help making a camera pan script, where you hold down MB1 and it pans around, so I had some trouble making it but eventually solved it!

I know this camera movement can probably be used in alot of games so, go make something great! I added documentation if you dont understand some stuff!

Also, I am aware i’m using mouse which is deprecated. just switch it out with userinputservice.

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
camera.CameraType = Enum.CameraType.Scriptable

-- The height of the camera when player spawns in
local CAM_HEIGHT = 25
-- How fast it pawns around when your dragging!
local PAN_SPEED = 10
local lastDragPosition

-- Makes the camera look down
camera.CFrame =,CAM_HEIGHT,0) * CFrame.Angles(-math.rad(90),0,0)

    dragging = true
    -- Remove the Y component of the Vector3 so it doesnt mess with the camera's Y pos
    lastDragPosition =,0,mouse.Hit.Position.Z)

    dragging = false

    if dragging then
        local delta =,0,mouse.Hit.Position.Z) - lastDragPosition
        camera.CFrame = + -delta * deltaTime * PAN_SPEED) * CFrame.Angles(-math.rad(90),0,0)

Looks nice! Definitely going to be very helpful in my next couple games!

1 Like

Quick question do u know how to screenpointtoray camera system like the one in rise of nations?