Greetings. I am attempting to make the Camera lerp to an object that it is tracking.
The object is controlled locally and uses BodyVelocity for it to move for the sake of example.
This is my code (very sloppy/pseudo code, please forgive):
Code
-- Please excuse the messy code
local RS = game:GetService("RunService");
local Goal = script.Goal;
local Camera = workspace.CurrentCamera;
Goal.Parent = workspace;
local CONST = 0.016666666666666667;
RS:BindToRenderStep("Test", Enum.RenderPriority.Camera.Value + 1, function (dt)
local delta = dt/CONST; -- This just make it work with variable framerates if using an unlocker, does not afffect jittering
local p = Goal.Position + Vector3.new(1,3,2);
local final = CFrame.new(p, Goal.Position);
Camera.CameraType = Enum.CameraType.Scriptable;
local speed = 0.5;
local rot = Camera.CFrame.Rotation;
Camera.CFrame = Camera.CFrame:Lerp(final, speed * delta); -- Introduces jitter, with or without delta
--Camera.CFrame = final; -- Does not have jitter
end)
Let’s take a look at what this causes to happen:
Apologies for low quality, had to downscale it so it would fit here. As I speed the object up you will notice it’s jittering. But the object itself is fine, it’s actually the camera that is jittering.
Normally I’d assume the solution would be to add delta time in but that’s what I’m doing.
Camera.CFrame = Camera.CFrame:Lerp(New, Speed * Delta)
On top of that, it’s in :BindToRenderStep()
loop set to Enum.RenderPriority.Camera.Value + 1
. So I’m not really sure what else I could be doing here to fix the stuttering. I’ve even tried using heartbeat delta, stepped delta, adding them together, etc, and it only very minutely improves the stuttering.
I should also mention that lerp()
is important here. It’s not very apparent since this example shows the object moving at a custom speed but when it’s attached to an object that moves around at varying speeds like a player or vehicle, it improves the look and feel.
So what could I be doing wrong here and what could I do to fix it? I’m pretty stumped. I should also note that I’m not a novice (proof) so I’m unsure if I’m having a major brain fart or if this is actually a complex issue, I’m guessing the former.
Here is the repro place:
delta correcting HELP.rbxl (1.1 MB)