What am I doing wrong with deltaTime and why is the camera stuttering?
Asked by
3 years ago Edited 3 years ago
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):
02 | local RS = game:GetService( "RunService" ); |
04 | local Goal = script.Goal; |
05 | local Camera = workspace.CurrentCamera; |
07 | Goal.Parent = workspace; |
09 | local CONST = 0.016666666666666667 ; |
11 | RS:BindToRenderStep( "Test" , Enum.RenderPriority.Camera.Value + 1 , function (dt) |
12 | local delta = dt/CONST; |
14 | local p = Goal.Position + Vector 3. new( 1 , 3 , 2 ); |
15 | local final = CFrame.new(p, Goal.Position); |
17 | Camera.CameraType = Enum.CameraType.Scriptable; |
21 | local rot = Camera.CFrame.Rotation; |
22 | Camera.CFrame = Camera.CFrame:Lerp(final, speed * delta); |
The result is that the faster the object moves, the more the camera vibrates/jitters.
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.
Uncopylocked place
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 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.