Hey all, I’m trying to create a car camera that will look something like this:
But, I cannot seem to figure out how to add the weight behind the camera. People have told me to use CFrame:Lerp(), but I cannot figure out how it would work for what I’m going for. Can anyone help me?
I would do something like this if I wanted to use CFrame:lerp():
local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
local rigidness = 0.25
local carPartToFollow = workspace.Part
local partTargetOffset = CFrame.new(0, 3, 8)
cam.CameraType = Enum.CameraType.Scriptable
function update()
local goal = carPartToFollow.CFrame*partTargetOffset
cam.CFrame = cam.CFrame:Lerp(goal, rigidness)
end
RunService.RenderStepped:Connect(update)
If you use the deltaTime argument which is passed by the RenderStepped event you can smooth it out, since the interval between each update will be slightly different each time in the example provided above.
If its starting to jitter like that at higher speeds it means that the values you are lerping are not correctly offset relative to your camera. At lower speeds it looks normal, but at higher speeds you aren’t actually interpolating the camera movement between the first position and the second position so it “teleports” to the second position without a smooth effect.
What you could try is making the smoothness a constant and then offsetting the camera by the smoothness on each renderstep so that your camera can gradually approach the destination without teleporting to it at higher speeds.