[Resolved] Custom camera script jitters at speed

Hello fellow developers!

I having a rather strange issue with the camera I’m making for my game - Drifter!
EDIT: Should probably include the game link, haha.

Here is a video showing the issue:
Take note how the car jitters when the car is moving at speed.
https://www.youtube.com/watch?v=p_9hlfB3sHo&feature=youtu.be

I don’t know what seems to be the problem. At first I thought it was a issue with performance but as you can see at the bottom right of the video - my CameraScript barely goes over 1% usage.

Here is the actual script:
(apologies for the poor-indentation - for some reason it won’t copy properly)

(UPDATED SCRIPT)

local cam = game.Workspace.CurrentCamera

local player = game.Players.LocalPlayer

local char = game.Workspace:WaitForChild(player.Name)

local hum = char:WaitForChild("Humanoid")

local pp = char.PrimaryPart or char:FindFirstChild("Head")

local rs = game:GetService("RunService")

repeat wait(.5) until hum.SeatPart and hum.SeatPart:IsA("VehicleSeat") and hum.SeatPart.Parent:FindFirstChild("Engine",true)

local seat = hum.SeatPart

local car = seat.Parent

local mp = car:FindFirstChild("Engine",true)

local carSize = car:GetExtentsSize().magnitude/10

local cOffset = CFrame.new(0,2,2)

local lastVel = Vector3.new()

local cf0,cf1

function Calc(dt)

local pos = mp.Position

local forward = mp.CFrame * CFrame.new(0,0,10).p

local backward = mp.CFrame * CFrame.new(0,0,-10).p

local vel = mp.Velocity

local pos2 = (pos+vel)

local speed = math.ceil((vel).magnitude * ((pos2-forward).magnitude > (pos2-backward).magnitude and 1 or -1))

local forwards = speed >= -5 and 1 or -1

local origin = mp.Position

local dir = (mp.CFrame.lookVector).unit*999 -- Car's facing direction

local vel = (mp.Velocity).unit*999 -- Car's velocity direction

--cf0 = CFrame.new(pos,pos + dir + vel / 100 * forwards) * cOffset

cf0 = mp.CFrame * CFrame.new(0,4 * carSize,8 * carSize * forwards) * CFrame.Angles(math.rad(-45 * carSize/5 * forwards),forwards < 0 and math.rad(180) or 0,0) * cOffset

cf1 = CFrame.new(pos,pos+(dir + vel / 100*forwards)) * CFrame.new(0,-5,-20 * forwards)

cf0 = cam.CFrame:Lerp(cf0:Lerp(cf1,0.1),0.1 + mp.Velocity.magnitude/1000)

--cf1 = cam.CFrame:Lerp(cf0:Lerp(cf1,0.6),0.2 + (mp.Velocity.magnitude/1000)) * CFrame.new(0,0,-10)

cam.CFrame = cf0--cam.CFrame:Lerp(cf0,0.8)

end

function Update(dt)

if hum.SeatPart and (hum.SeatPart:IsA("VehicleSeat")) then

if cam.CameraType ~= Enum.CameraType.Scriptable then

cam.CameraType = Enum.CameraType.Scriptable

end

Calc(dt)

elseif cam.CameraType == Enum.CameraType.Scriptable then

cam.CameraType = Enum.CameraType.Custom

end

end

rs:BindToRenderStep("VehicleCam",Enum.RenderPriority.Camera.Value-1,Update)

EDIT 2:

So after some experimenting I managed to improve the camera a little bit.
It doesn’t jitter as much, but I definitely don’t believe it has anything to do with the new Camera Scripts.

On my personal computer (that has decent specs) the jitter is negligiable. However when I switch vehicles to the Truck in my game, the jitter increases.
Even more so, when I use a laptop to run the same place - the jitter is exponentially worse.

I have a feeling its related to the physics usage in my game, but if that was the case, wouldn’t the default camera jitter all the same?

I’ve update the script with what I have at the moment.

Any insight would be greatly appreciated.

1 Like

It’s due to the new starterplayerscripts (i.e a new camera and control script).

Basically, changing the camera type to scriptable no longer functions exactly how it did before. In the linked thread, it gives you a link to the old player scripts that you can place in temporarily to fix the issue until you can change your script to be compatible with the new scripts.

Hope this explained it :slight_smile:

2 Likes

Great I will try this. Thanks!

Heya SkyDiver.

So I looked through the new scripts and, well its going to take me a while to figure them out, so I reimported the old camera and controller for now, but still have the same issues.

Has the Scriptable camera type itself changed somehow?..
I’m not sure what is going on.

1 Like

So long as you’ve downloaded this link:
https://devforum.roblox.com/uploads/default/original/4X/2/a/4/2a4bc3c219809aaf3c4e1ea8d80261711aac45d6.rbxl
and placed the CameraScript and ControlScript under StarterPlayerScripts, everything should return to normal before the update.

If this isn’t the case, then it’s likely a problem with your own code.

Have you seen Fixing Jittery CFrame Lerping
I honestly don’t know much but it looks like your doing a lerp inside of another lerp? Doesn’t seem right but :man_shrugging:
It mentions setting the render priority which might help some.

1 Like