Camera lags behind where Humanoid.CameraOffset should be

Hello, I’m setting Humanoid.CameraOffset every render frame to keep it perfectly aligned with the character’s eyes (this adds animation bobbing to the camera and a few other fun things, but I’m getting off track). The problem I’m having is that the camera update seems to lag behind by a frame or two. This happens in both local and online environments.

Outdated/probably irrelevant information

Here is a dump of the script (also included in the repro file below) I’m using to change CameraOffset, in case this is a problem on my end:

wait()

local plr = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera

_G.services = {
	run = game:GetService("RunService")
}

repeat wait() until plr.Character
local char = plr.Character

local function UpdateLookVertical(target,theta)
    local width = char.Humanoid.BodyWidthScale.Value
    local height = char.Humanoid.BodyHeightScale.Value
    local headScale = char.Humanoid.HeadScale.Value
    
    local neckC0 = CFrame.new(0, (0.5*height) + (0.25*headScale), 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
    local waistC0 = CFrame.new(0, 0.2*height, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
    
    target.Head.Neck.C0 = neckC0 * CFrame.fromEulerAnglesYXZ(theta*0.75, 0, 0);
    target.UpperTorso.Waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(theta*0.25, 0, 0);
    
    if target == char then
	char.Humanoid.CameraOffset = char.HumanoidRootPart.CFrame:vectorToObjectSpace(char.Head.Position - char.HumanoidRootPart.Position)
	    + char.HumanoidRootPart.CFrame:vectorToObjectSpace((char.Head.CFrame.UpVector*0.25*headScale) + (char.Head.CFrame.LookVector*0.4*headScale))
	    - Vector3.new(0, (1.5/height) + (0.5/headScale), 0)
    end
end

_G.services.run:BindToRenderStep("UpdateViewModel",Enum.RenderPriority.Camera.Value - 1,function() UpdateLookVertical(char,math.asin(cam.CFrame.LookVector.Y)) end)

Here is a repro place file (MinimumRepro.rbxl) (100.6 KB) and the repro steps:

  1. Start a test server and zoom into first person. Look down and spin the camera around the Y-axis. Note the choppy movement.
  2. Disable game.StarterGui.ClientCore and start another test server. Zoom into first person and repeat, note the character stays perfectly aligned with the camera now that CameraOffset is no longer being changed.

After running the repro myself again and disabling the script that modifies CameraOffset after looking down (so CameraOffset is still set to a non-default value but isn’t being actively updated), the issue still persists; it seems that so long as the camera’s target point is off centre from the character’s head, the issue shown in the video below occurs:

If you still want to run the repro yourself, the file and instructions are in the details above.

Edit: Cleaned up code formatting. | 2: Fixed title. | 3: Added video. | 4: Updated bug report with new information and changed title.

1 Like

I could replicate although it wasn’t as severe as you are explaining it to be (almost unnoticeable).

You can probably make it a tiny bit smoother by hooking up the function to fire anytime the camera or camera subject changes.

1 Like

I’m already running it every frame, directly before the camera is supposedly updated (I’ve fiddled with the RenderPriority with no luck, too) - I don’t think running it any more frequently or at different intervals will really help. Interesting that it wasn’t all that noticeable to you, though.

1 Like