Camera:Interpolate help

1. What do you want to achieve? Keep it simple and clear!
Well, i want to make a simple smooth camera movement for my car chassis system.

2. What is the issue? Include screenshots / videos if possible!
The camera seems to ‘lag’, notice (video below) that the car itself is the only one that’s lagging, if you take a closer look at the baseplate or horizon you can see that it is not lagging at all.
When disabling the camera script the car is moving smoothly again.

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, I did, I couldn’t find anything related to this topic.
I’ve tried using the weighted linear interpolation instead:

v = ((v * (N - 1)) + w) / N

It has made it a bit smoother but yet still was too rough.

I also tried using Tween Service but it also failed.
No more clues from me.

This is a piece code i’ve been using:

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = 50

local CamPart = veh.Body.cam

--//Service
local Service = {}

Service.Tween = game:GetService("TweenService")
Service.Run   = game:GetService("RunService")

threshold = 1

Service.Run.RenderStepped:Connect(function()
	if Values.Velocity.Value.Magnitude > threshold then
		Camera:Interpolate(
			CamPart.CFrame,
			veh.Body.focus.CFrame,
			.1
		)
	end
end)

Thanks in advance, a detailed explanation would be very appreciated.

2 Likes

To lerp the camera, you could store the camera’s last CFrame and lerp from that to the desired CF every frame which would look something like:

local DAMPING_FACTOR = 6
local RS = game:GetService("RunService")
local lastCF

RS.RenderStepped:Connect(function(dt))
     local currentCF = camera.CFrame
     local desiredCF = (lastCF or currentCF):Lerp(DAMPING_FACTOR * dt)
     camera.CFrame = desiredCF
     lastCF = desiredCF
end

Adapt this to your application.

Don’t use camera:Interpolate. I actually have no idea why this is not deprecated yet.
You can use @UntitledProtocol’s method, or you can use TweenService to tween the camera.

Can you explain how to set the script up to the chassis, the reason being is that you have unknown global words e.g veh and values that are not backed up with variables. If I can get it to work then I can start to try solutions.

If i were you I would just use bind to render step and use the camera priority to help with it lacking behind.
You also have the time set to .1 and not to the delta time which can be causing it to be left behind for a bit.

If you don’t upload the full code we can’t help you