Hola fellow Robloxians. I’ve been working on a game that utilizes a force shift-lock mode by using RunService. It technically works, but there’s an issue.
It’s overall, just very glitchy. When moving the camera around, your character kind of glitches back and forth, the entire screen does too, to an extent, but I have a reasonable doubt that the camera is the issue, and rather that everything glitches because of your head glitching, which is where the camera is based off of in First Person. This is a video of the janky-ness occuring:
As you can see, everything works fine, but your character has trouble keeping up with the camera turning. How could I fix this?
EDIT: Oh gosh, I forgot the code completely! It’s pretty simple though, here it is:
Script in StarterCharacterScripts:
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local humanoid = player.Character.Humanoid
runService.RenderStepped:Connect(function()
humanoid.CameraOffset = Vector3.new(2.5,0.5,2)
end)
I then configured a part of the CameraModule:
function CameraModule:Update(dt)
if self.activeCameraController then
if game.Players.LocalPlayer.PlayerScripts.ShiftLockToggle.ShiftLockToggle.Value == true then --Edited code, simple if-else statement
self.activeCameraController:SetIsMouseLocked(true)
else
self.activeCameraController:SetIsMouseLocked(false)
end
You don’t need to make a connection to change the camera offset. Idk if I’m right or wrong but :Update() runs every frame just like RenderStepped, try changing the offset in the update function instead of creating a new one connection and then changing the offset.
Maybe you can try using the BindToRenderStep function instead of RenderStepped
Here is an example, although it is not the shift lock feature, this is an alternative.
local runService = game:GetService('RunService')
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local character = player.Character or player.CharacterAdded:Wait()
local function adjustCamera()
camera.CFrame = CFrame.new(character.Torso.CFrame * CFrame.new(0, 0, 5)
end
runService:BindToRenderStep('CameraBehindPlayer', 201, adjustCamera)
We’re getting somewhere now. The lag doesn’t occur anymore, but despite me changing the CFrame.new() values, it always goes directly behind the player.