Basically I wan’t to make it so if a player presses left alt they can switch their shiftlock from right to left. I’m just not sure how to actually switch shiftlock from right to left. Any help is greatly appreciated!
Still struggling with this. Any help is greatly appreciated. I’ve tried setting the cameraoffset to the opposite side of the players shoulder but it looks weird.
I found a script for this right now.
Put a new local script in StarterCharacterScripts and paste this inside:
--//Services local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") --//Variables local plr = Players.LocalPlayer local char = script.Parent local hum = char:WaitForChild("Humanoid") local root = hum.RootPart --//Controls local isEnabled = false --//Functions local function shiftLock(active) --Toggle shift.lock function if active then hum.CameraOffset = Vector3.new(-1.75, 0, 0) -- I assume this is about the right camera offset. hum.AutoRotate = false --Disable the automatic rotation since we are the ones setting it. RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function() UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Set the mouse to center every frame. local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, y, 0) --Set the root part to the camera's rotation end) else hum.CameraOffset = Vector3.zero --Move the camera back to normal. RunService:UnbindFromRenderStep("ShiftLock") -- Allow mouse to move freely. UserInputService.MouseBehavior = Enum.MouseBehavior.Default -- Let the mouse move freely hum.AutoRotate = true --Let the humanoid handle the camera rotations again. end end UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if input.KeyCode ~= Enum.KeyCode.LeftAlt then return end isEnabled = not isEnabled shiftLock(isEnabled) end)
Whenever LeftAlt is pressed, the camera offset is moved and the mouse is locked to the center.
Tried this and theres one issue.
This only works if you press ALT while shiftlock is not active. If you press it while its active it just puts it onto your head. Example:
actually I can just simply get the offset and multiply it by 2 everytime alt is pressed and make it so it only works when shift lock is enabled. Thank you for the help!
No problem. I can also make it so that if you press shift for shiftlock it will change it. If you want me to do that you can just tell me.
I managed to get it to work. Thank you though.
I have come across one issue though. When the cameraoffset is applied the camera acts choppy as you can see here:
I’m not sure how to fix this.
I did a little bit of searching and found out its a problem with the speed of RenderStepped. To fix it I need to fork the PlayerModule and change a bit of scripts. When I’m done I’ll reply back but I probably won’t finish today.
I managed to fix this perfectly using the built in functions.
Download this rbxm file and put it in StarterPlayerScripts:
PlayerModule.rbxm (124.4 KB)
On an unrelated note, Roblox should really optimize some of the PlayerModule scripts.
Works like a charm however there is one issue. I already have functionality to where pressing left alt switches sides while shiftlock is on. But when I put that in pressing ALT turns off shiftlock and I have to press it again to get the left side. Is there anyway you can remove the leftalt shiftlock and just have the camera stuff? I already have the functionality to switch sides.
I’m sorry but I don’t think I can do this. If someone else wants to find a way how to do this feel free to.
What did you do exactly to make the camera work with left sided shiftlock? Maybe I could implement it to work with my version.
In the ShiftLock module, I detect if they were holding LeftAlt and then change the CameraOffset accordingly, and vice-versa for the other keys.
Thats exactly what I do in my code. What makes the camera follow it smoothly?
You have to change it in the actual ShiftLock module. It does calculations based on the deltaTime and cameraOffset to determine where to position the character.
Oh ok I see. Thank you for all the help!