Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a Shift-Lock like Camera?

Asked by 6 years ago
Edited 6 years ago

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)
0
so much math.. hiimgoodpack 2009 — 6y
0
i probably seem stupid to scripters like you who know alot of math (compliment), but this still doesnt work LifeInDevelopment 364 — 6y
0
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) chess123mate 5873 — 6y
0
well im multiplying it by torsooffset because its a third person camera and the camera is offsetted from the torso LifeInDevelopment 364 — 6y

Answer this question