I have a custom camera and I’ve always had this shake when trying to tween it every frame which I couldn’t figure out how to fix so I moved to BodyGyro and BodyPosition which was completely fine, but I’d like to re-visit tweening as it’d be cleaner since I wouldn’t need a physical part. Any ideas on how to get rid of the shake?
It looks to be more of an issue with you constantly overriding the tween. By the way the jittering happens, it looks like it’s using a different start point than what it should.
I recently made a 2D camera that used TweenService, so I know it works fine. I also think I had to modify the code a bit for when the goal of the tween has been reached, and the camera is sitting still.
I believe I did something like this (but this is probably inaccurate):
local CurrentGoal
local CurrentTween
RenderStepped:Connect(function()
local LocalGoal = CFrame.new(CameraCFrame.p, CameraFocus.p)
if LocalGoal ~= CurrentGoal then -- if it should make a new tween
local Tween = TweenService:Create(Camera, Info, {CFrame = LocalGoal})
CurrentTween = Tween
CurrentGoal = LocalGoal
Tween:Play()
Tween.Completed:Connect(function()
if CurrentTween == Tween then -- if tween is still running
CurrentTween = nil
end
end)
elseif not CurrentTween then -- if the camera isn't tweening, and there isn't a new target
Camera.CFrame = CurrentGoal
end
end)
This code should get rid of the shake by targeting the exact same goal and only tweening when it needs to. If you’re still having issues I’ll dig up the working version tonight when I get home
What you can do is manually interpolate the current position/rotation to the goal every frame.
Here is a crude example:
local current = camera.CFrame
local goal = CFrame.new(CameraCFrame.p,CameraFocus.p)
camera.CFrame = current:lerp(goal, 0.5)
There are better ways of doing this imo (using scripted springs) but this works well enough and simulates the same thing that springs would accomplish.
Try this: instead of connecting the function to :RenderStepped, properly bind it to RenderStep with :BindToRenderStep. That way, you can set its priority.
I’m betting that your character updates at a RenderPriority of 300 (see Documentation - Roblox Creator Hub for more info), so the camera should update at a priority below that. (lower priority values get executed earlier)
RunService:BindToRenderStep(
"camera"
Enum.RenderPriority.Camera.Value,
yourUpdateFunction -- this is the function you would normally connect to :RenderStepped
)
I’ve already been doing this with BodyGyro and BodyPosition for a while and it worked perfectly, but the problem with that is that you need to have a physical part. I haven’t used springs yet, do they need a physical part or do they only need an attachment?
I don’t mean SpringConstraints, I meant some sort of spring module.
I’ll admit that I barely know what I’m talking about at this point since I’ve only ever used springs for simulating gun recoil and not for camera interpolation. I really didn’t expect your problem to be harder than playing around with :lerp and RenderStepped priorities.