I have security cameras which players can toggle through, when they are on a camera i want to give them the ability to pan around, but only to a certain limit so the camera does not look 180 degrees behind or too far down. I would like a slight delay.
I cannot find a way which both has the panning feature and the limit.
I am using runservice to update the camera, I have been using lerp to smoothly move the camera but I do not know if it is the best. I have been using math.clamp for the limits.
My main problem is what to do with these pieces.
Example of current code without limits.
function camera_pan:follow_mouse(cam:Part)
runservice_connection = RunService.RenderStepped:Connect(function()
local mouse_p = player:GetMouse().Hit
local look_at_rotation = CFrame.lookAt(cam.Position, mouse_p.Position)
local target_rotation = cam.CFrame:Lerp(look_at_rotation, 0.1)
cam.CFrame = target_rotation
workspace.CurrentCamera.CFrame = cam.CFrame
end)
end
side note: Iām not sure if i like lerp as the speed of the camera changes depending on mouse distance. I just want it to be smooth. Like a rainbow-six-siege camera.