Third time is the charm, because this is a fatal flaw of my game and no help has been found yet.
I am making a forced Shift lock for my game. I accomplish this by setting MouseLocked to true in my CameraModule script:
function CameraModule:Update(dt)
if self.activeCameraController then
if game.Players.LocalPlayer.PlayerScripts.ShiftLockToggle.ShiftLockToggle.Value == true then
self.activeCameraController:SetIsMouseLocked(true)
That works fine. I get this when I do that:
But we obviously want an offset for shiftlock, so you can look over your shoulder like this:
So since I also wanted a camera sway when you walked, I made a script in StarterCharacterScripts that updates every frame to add in the sway, and also create a camera offset as such:
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local humanoid = player.Character.Humanoid
local gameSettings = UserSettings().GameSettings
local mouse = player:GetMouse()
local head = player.Character:WaitForChild("Head")
local runService = game:GetService('RunService')
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local character = player.Character or player.CharacterAdded:Wait()
runService.RenderStepped:Connect(function()
local currentTime = tick()
if camera.CameraType == Enum.CameraType.Follow and humanoid.MoveDirection.Magnitude > 0 and humanoid.WalkSpeed > 0 then
local swayX = math.cos(currentTime * 15) * 0.3
local swayY = math.abs(math.sin(currentTime * 15) * 0.3)
local sway = Vector3.new(swayX + 4.5, swayY, 1)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(sway, 0.25)
elseif camera.CameraType ~= Enum.CameraType.Follow or humanoid.MoveDirection.Magnitude == 0 or humanoid.WalkSpeed == 0 then
local offsetStandard = Vector3.new(4.5, 0, 1)
humanoid.CameraOffset = humanoid.CameraOffset:Lerp(offsetStandard, 0.25)
end
end)
Now my camera would have an offset as expected, but also the character glitches pretty bad.
So just in case it was the sway, or the fact I was updating it every frame, I simplified the offset for troubleshooting purposes:
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local humanoid = player.Character.Humanoid
humanoid.CameraOffset = Vector3.new(4.5, 0, 1)
Yet even with this oversimplification, the glitched out character persists.
Some extra info if you need to replicate this:
In StarterPlayer, the CameraMovementMode is Follow
ForceFirstPerson is off
Camera Minimum and Maximum distance are both 4.
If you have anything of use please reply with it. I’ve been at this for a while and no other devForum threads have this issue or the solution.