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?
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.