Character is jittery when CameraSubject is set to non-humanoid

I’m trying to make the camera subject a part that follows the player to so that there is a slight delay whenever the player moves. The actual movement is very smooth, it’s just that now the player’s character is stuttering and jittering when it moves.

Here’s the code:

RunService:BindToRenderStep("camFollow",Enum.RenderPriority.Camera.Value - 1, function(dt)
		self.camera.CameraSubject = self.camPart
		
		local startPos = self.camPart.Position
		
		local finishPos = (self.character.HumanoidRootPart.CFrame + Vector3.new(0,1,0)).Position + self.character.Humanoid.CameraOffset
		local magnitude = (startPos - finishPos).Magnitude
		local distance = (9 + magnitude/10)
		
		self.camPart.Position = self.camPart.Position:Lerp(finishPos, math.min(dt * distance,magnitude))
	end)

When I set the CameraSubject to the player’s Humanoid, it stops jittering.

I read this post, and it said I have to set the moving part (character)'s position before the camera updates. But since the player moves around using core roblox scripts, I can’t simply set the character’s position before the camera updates.

This is what it looks like:

Does anyone know how to fix the character stuttering and jittering when I set the CameraSubject to a non-humanoid?

Put this code outside of the function to start with.

1 Like

That line of code doesn’t have any effect because the camera subject is always going to be the part following the character.

Anyways, I stopped setting the camera subject to the camera part every frame and the character is still jittering.

What if you created a table of all old positions, and then after like 100 steps, then you move the camera there

1 Like

like this:

self.camera.CameraSubject = self.camPart
local oldpos = {}
local delaystep = 100
RunService:BindToRenderStep("camFollow",Enum.RenderPriority.Camera.Value - 1, function(dt)
    delaystep -= 1
    if delaystep <= 0 then
	    local startPos = self.camPart.Position
        table.insert(oldpos, startPos)
	    self.camPart.Position = oldpos[1]
        table.remove(oldpos, 1)
    end
end)
1 Like

Sorry but this just drops the framerate
wait let me try it

1 Like

is this how I do it?

local startPos = self.camPart.Position
local finishPos = (self.character.HumanoidRootPart.CFrame + Vector3.new(0,1,0)).Position
local magnitude = (startPos - finishPos).Magnitude
local distance = (9 + magnitude/10)

--TweenService:Create(self.camPart,TweenInfo.new(0.05),{Position = self.camPart.Position:Lerp(finishPos, math.min(dt * distance,magnitude))}):Play()
local pos = self.camPart.Position:Lerp(finishPos, math.min(dt * distance,magnitude))
--self.camPart.Position = self.camPart.Position:Lerp(finishPos, math.min(dt * distance,magnitude))
	
delaystep -= 1
if delaystep <= 0 then
	local startPos = self.camPart.Position
	table.insert(oldpos, pos)
	self.camPart.Position = oldpos[1]
	table.remove(oldpos, 1)
end

It doesn’t drop the framerate but the character is still lagging

Okay so I found another way to do this.

Basically, I got the offset between the CFrame of the character’s HumanoidRootPart and the CFrame of the part that is following the player, and tweened the humanoid’s CameraOffset to that offset.

RunService.RenderStepped:Connect(function(dt)
	local startPos = self.camPart.Position
	local finishPos = (self.character.Head.CFrame).Position
	local magnitude = (startPos - finishPos).Magnitude
	local distance = (9 + magnitude/10)
		
	self.camPart.Position = self.camPart.Position:Lerp(finishPos, math.min(dt * distance,magnitude))
		
	local camOffset = self.character.PrimaryPart.CFrame:ToObjectSpace(self.camPart.CFrame).Position
		
	TweenService:Create(self.character.Humanoid,TweenInfo.new(0.1),{CameraOffset = camOffset}):Play()
end)

It now achieves the same behavior in the video I sent and doesn’t cause the player’s character to jitter or stutter.

Thanks for the help though!

2 Likes

Glad you found the solution to your problem (even if I didn’t help much)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.