I'm trying to recreate shift lock in my custom camera, but im trash at anything that requires math or cframes. I've had a go and I know I need to use lockcenter on the mouse and use userinputservice to check where the mouse is moving, but the camera is messed up. How would I modify this to make it work?
-- Scripted by LifeInDevelopment
local userInputService = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local torsoOffset = CFrame.new(0, 3, -5)
local maxSensitivity = 10
local xSensitivity = 5 -- max is 10
local ySensitivity = 5
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
userInputService.InputChanged:connect(function(inputObject)
local character = player.Character
local torso = character:FindFirstChild('Torso') or character:FindFirstChild('UpperTorso')
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local deltaX, deltaY = inputObject.Delta.x * (xSensitivity/maxSensitivity) , inputObject.Delta.y * (ySensitivity/maxSensitivity)
camera.CFrame = torso.CFrame * torsoOffset * CFrame.Angles(deltaX, 0, 0) * CFrame.Angles(0, deltaY, 0)
end
end)

4 comments
so much math..
i probably seem stupid to scripters like you who know alot of math (compliment), but this still doesnt work
inputObject.Delta.x is in pixels, but CFrame.Angles wants radians. You probably want something closer to CFrame.Angles(0, deltaX/100, deltaY/100), though I have no idea what numbers you'd want exactly (it's not likely to be /100), and idk if you should have * torsoOffset in there or not. Instead of xSensitivity/maxSensitivity, you probably need math.min(xSensitivity, maxSensitivity)
well im multiplying it by torsooffset because its a third person camera and the camera is offsetted from the torso