Custom first person camera sporadic jitter

I’ve been working on a custom first person camera for my game that introduces smooth mouse movement, up/down and left/right head bob, and tilting. Recently, the character model visible in the camera has begun to jitter erratically when looking around. This is behaviour that I had previously not experienced prior to last Wednesday’s Roblox update (or, at least this is what I believe). To double check this assumption, I went back to earlier versions of the script that I know for a fact were working and had not been touched since the update, and they are the same.

The jitter is actually much harder to reproduce in game as opposed to testing in studio but is still a problem. It’s also more prevalent on lower capped framerates (video is done in 60fps)

Here is the code snippet that applies the changes to the camera, in a function bound with BindToRenderStep with + 1 priority on the Camera

local yScaleVal = yScale(mouseYL)
	mouseXL = numberLerp(mouseXL, mouseX, smoothnessFactor * dt * lerpVal)
	mouseYL = numberLerp(mouseYL, mouseY, smoothnessFactor * dt * lerpVal)
	tilt *= yScaleVal
	tilt = numberLerp(tilt, 0, 5 * dt)
	sineX *= yScaleVal
	sineY *= yScaleVal
	sineXL = numberLerp(sineXL, sineX, dt * 25) * walkPercent
	sineYL = numberLerp(sineYL, sineY, dt * smoothnessFactor * 4) * walkPercent
	
	fakeHead.CFrame = character.Head.CFrame
	local rX, rY, rZ = camera.CFrame:ToOrientation()
	if seizeCamera.Value == false then HumanoidRootPart.CFrame = CFrame.Angles(0, rY, 0) + HumanoidRootPart.Position end
	local pos = offsetPart.Position
	
	if seizeCamera.Value == true then 
		sineYL, sineXL, tilt = 0, 0, 0
		pos = camHoldRefs[seizeCamera:GetAttribute("camHoldRef")].Position + seizeCamera:GetAttribute("camHoldPos")
	end
	
	--pos += Vector3.new(0, sineYL, 0)                                   			   -- vertical bob
	camera.CFrame = CFrame.new(pos)
		* CFrame.Angles(0, math.rad(mouseXL / (2.5 / sensitivity)), 0)  		   -- horizontal motion 
		* CFrame.Angles(math.rad(mouseYL / (2.5 / sensitivity)), 0, 0)  		   -- vertical motion
--		* CFrame.new(sineXL, 0, 0)												   -- horizontal bob
--		* CFrame.Angles(0, 0, tilt)								   		           -- tilt

If anyone could provide some insight on this that would be legendary

2 Likes

I feel like this could be an issue with how the mouse reacts in first person. When you look around in first person, you can sometimes see the mouse look like its jittering back and forth from the center of the camera to the direction that your camera is moving. Since part of your script relies on the position of the mouse, that could be part of the problem.

Have you tried testing it in the published game (not in studio)?

1 Like

I went and did some extensive testing in game and not in studio. As it turns out, you are correct in this case. I didn’t notice the extreme jitter that I did in studio (however there was some minor stuff that I still believe is a problem)

Regardless, it’s unfortunate. Is there a work around that can make mouse delta more reliable or another way to collect the player’s mouse movements?

Well, I have some interesting updates.

I recorded some sessions of the jitter and analyzed them frame by frame with console prints for reference. It turns out that every frame before the jitter begins is doubled up (as in, when going frame by frame in the video, each frame shows the camera in a different position from the last until the frame before the jitter, which shows two frames in identical positions). Then, after the identical frames, the next frame shows the erratic motion. I also observed that during the double frames no console prints came in, despite them being tied to the Render function. This makes me think that when testing in Studio I’m getting unreliable playback in the form of skipped frames? Honestly, it’s all a bit more technical then what I an equipped to handle. I’m really not sure how to fix this issue or if it’s something I can even fix.

Again, I only experienced this AFTER the April 26th Wednesday update. I still have suspicions that that is the latent cause here.

1 Like

Nice job, this is really cool, I can see how I can use the same machine in my game.

Yea it just sounds like something that requires some frame rate manipulation of the view model to fix. I don’t know exactly what you would do to get into that but if the view model movement is skipping frames I feel like its an issue with fluctuating frame rates.

this is caused likely because the character is being controlled by both a loop and the physics. they’re updating offset from each other so you can view the jitters when the framerate fluctuates

While this might be the explanation for the minute amounts of inconsistency seen in the video, I believe the large jittering motions are caused by the weird mouse movement that Swagrid referred to in the first reply.

A video for reference

I’ve since done large reworks to my camera code and no longer experience this issue, but I observe the funky mouse movement while using Studio everyday and wonder what other problems it’s causing.