I’m trying to make a shift lock system & it works decently but there are two issues:
-
When you move the camera outside of shift lock, and then go back in shift lock, it doesn’t save your camera’s position so it ends up putting the camera in the last position it was in when you were in shift lock, video
-
While in shift lock you can tilt your camera all the way up so far that it goes upside down, video
I’m more worried about the first issue though and I want to fix that one first
local CAS = game:GetService('ContextActionService')
local UIS = game:GetService('UserInputService')
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local RS = game:GetService('RunService')
local shiftlock = false
local rotation = Vector2.new()
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl and shiftlock == false then
shiftlock = not shiftlock
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
SHIFTLOCKCAM = RS.RenderStepped:Connect(function()
currentZoomDistance = (character.Head.Position - camera.CFrame.Position).Magnitude
local delta = UIS:GetMouseDelta()
rotation = rotation + Vector2.new(-delta.Y, -delta.X)
local cameraOffset = CFrame.new(2.2, 0, currentZoomDistance)
camera.CFrame = CFrame.new(character.Head.Position) * CFrame.Angles(0, math.rad(rotation.Y), 0) * CFrame.Angles(math.rad(rotation.X), 0, 0) * cameraOffset
end)
UIS.InputChanged:Connect(function(input, gpe)
if gpe or input.UserInputType ~= Enum.UserInputType.MouseWheel then
return
end
local scrolledUpwards = (input.Position.Z >= 0)
if scrolledUpwards then
currentZoomDistance -= 0.35
else
currentZoomDistance += 0.35
end
currentZoomDistance = math.clamp(currentZoomDistance, 3, 16) -- make sure it doesn't go lower than 3 or higher than 16
end)
elseif input.KeyCode == Enum.KeyCode.LeftControl and shiftlock == true then
shiftlock = not shiftlock
UIS.MouseBehavior = Enum.MouseBehavior.Default
UserSettings().GameSettings.RotationType = Enum.RotationType.MovementRelative
SHIFTLOCKCAM:Disconnect()
end
end)
If there’s a better way to do this, I’ll happily take any suggestions