How to make a camera movement system?

so the system I am trying to figure out how to make is a panning system, where if you mouse goes to a certain part of the screen it starts to pan the camera to the left or right. and I am trying to figure out how to make it stop at a certain point. how can I go about achieving this using RunService?

1 Like

Do you mean that your camera is following your mouse?

yeah, and when your mouse gets close to the end of the left or right side, it starts to rotate the camera in that direction until the limit is reached

1 Like

yeah, this script is being using for a menu screen with multiple options, so i need the camera to pan to whereever the options can be selected

1 Like

You can watch this video created by ConfidentCoding if it’s what you mean:

You can connect to the mouse movement using UserInputService.InputChanged and simply check if the position of the input object is either 0 in the x/y/both direction or if the x/y/both of the position is the size of the viewport (Camera.ViewportSize). Hope this helped!

1 Like

that helps for one part, but for the panning around the screen, i kinda want this effect but with rotation.

if you want to control how close the rotation follows the mouse, you can use Lerp

you can try doing this:

local fractionToPointAtMouseDestination = 0.5 -- halfway between

local mousep = mouse.Hit.p
local camera = workspace.CurrentCamera

rs.RenderStepped:Connect(function()
     local portion = CFrame.new(camera.CFrame.p, camera.CFrame.p + (mousep - camera.CFrame.p).Unit)
     camera.CFrame = CFrame.new(camera.CFrame.p, camera.CFrame:Lerp(portion, fractionToPointAtMouseDestination).p)
end)

is .p the position of the mouse?

1 Like

Yep

(30 characters)
(30 characters)