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)