Jittery character movement?

I’m currently having difficulty pinpointing the exact cause of this jittery character movement with a custom camera script:

I’ve tried many other resources that explain the same problem however there were no solutions for preventing this kind of behavior. It occurs both in studio and in-game, and becomes worse in higher velocities.

This also occurs even if I remove the smooth feature using lerp as the camera feels like it is stuttering. Any ideas on how I could solve this? It is just using the default PlayerModule to move the character.

1 Like

A code sample would be appreciated, although without one the most I can make out is that the camera is repeatedly trying to smoothly tween to the new characters position but the movement of the character is making it jittery since the camera cannot keep up.
Not entirely sure, but I’ve seen this before.

The camera is not the one jittering, it’s the character itself. Tested it with someone and I could clearly see their jitter as well.

Here is part of the code that handles updating:

function cameraModule:UpdateCamera(dt)
    local camera_cframe = CFrame.new()
    for i = 1, #instances do
        camera_cframe *= instances[i](dt)
    end

    return camera_cframe
end


function cameraModule:StartCamera()
    RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function(dt)
        camera.CFrame = self:UpdateCamera(dt)
    end)
end

Solving it:

local function Lerp(a, b, t)
    return a + (b - a) * t
end


local function Solve()
    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

    local rootX = root.Position.X
    local rootY = root.Position.Y
    local rootZ = root.Position.Z

    rootX = Lerp(px, rootX, .2)
    rootY = Lerp(py, rootY, .2)
    rootZ = Lerp(pz, rootZ, .2)

    local ch = math.cos(angleX)
    local sh = math.sin(angleX)
    local cb = math.cos(angleY)
    local sb = math.sin(angleY)

	local m12 = sh*sb
	local m13 = sh*cb
    local m32 = ch*sb
    local m33 = ch*cb

    local local_x  = ch*2 + m12*2 + m13*14 + rootX
    local local_y = cb*2 + -sb*14 + rootY
    local local_z = -sh*2 + m32*2 + m33*14 + rootZ

    px = rootX
    py = rootY
    pz = rootZ

   local result = workspace:Raycast(
        Vector3.new(rootX, rootY, rootZ),
        Vector3.new(local_x - rootX, local_y - rootY, local_z - rootZ),
        raycast
    )
    if result then
        return CFrame.new(
            local_x + .1, local_y + .1, local_z + .1,
            ch,     m12,     m13, 
            0,      cb,      -sb, 
            -sh,    m32,     m33
        )
    else
        return CFrame.new(
            local_x + .1, local_y + .1, local_z + .1, 
            ch,     m12,     m13, 
            0,      cb,      -sb, 
            -sh,    m32,     m33
        )
    end
end

Something to note is that it also jitters when I remove lerp and/or when I switch it to CFrame.

There doesn’t seem to be any part of the code that edits the position of the character whatsoever, right? From my guess, it’s either the camera really is being weird or the core Roblox movement scripts are having a hard time compensating for your camera (which I doubt, but I don’t really know much regarding the details of those.)

Also, by ‘switch it to CFrame’ do you mean that this occurs even when you directly set the camera position without lerping or tweening it there?
Could I also have some information on the “instances” table referenced in the :UpdateCamera() method? (e.g some code thats used to set it)
Apologies if I’m being unhelpful, I’m currently about as stumped as you are. Trying to look into it.

There is no other bits of code that edits the position of the character whatsoever, and i’ve checked that Solve() is the only function in the instances table. When I meant to “switching it to cframe”, I meant not using cframe operations (excluding where I construct it in the end). As for directly setting the camera position without lerping, it has the same behavior.

What other scripts are in this place, and what are their purpose? I highly doubt the camera could cause this alone unless the Roblox core movement script just really hates you.

The other codes in place are just my framework, my gameplay mechanics controller, (but this jittering was there before it existed). Everything else is just parts of my game and/or systems that don’t even reference the character’s positions/cframes.

EDIT: Forgot to note that this behavior is completely gone after my custom camera is removed.

I’ve been pretty puzzled after looking into it further. However, I was wondering: what camera type is the camera set to?

Camera type is scriptable. Checked in the explorer as well.

Try going through each camera type and setting them in the script and see if anything changes, the camera type could tie to something movement related in the core scripts.

I doubt this is the problem, but I went ahead and tried but it still jitters. Tried removing the CameraModule from the PlayerModule as well, still the same problem. I’m honestly lost.