Camera is twitches

I tried to do camera system in car but it’s too twitches.

Here video

Script

task.spawn(function()
	while task.wait(0.1) do
		if self and self.Seat.issit == true and self.plrdata.hum.SeatPart then
			local calcu = self.plrdata.hum.SeatPart.Position-lastposes
			self.DataStorage.Main.AddPose.Value = calcu 
			lastposes = self.plrdata.hum.SeatPart.Position
		end
	end
end)

I don’t understand why it happening. But the problem is in this script

2 Likes

make sure the camera updates before the frame is rendered by binding it to PreRender

game:GetService("Runservice").PreRender:Connect(Function()
end)
1 Like


too same

1 Like

well, how is the position of the camera calulcated? (example code please)

i’m already sended script (which is the problem here)
(value changes twitches)

um, well I mean what is the purpose of lastposes and self.DataStorage.Main.AddPose.Value and also where is the Camera’s CFrame is updated exactly, there might be synchronizing issues or even problems in how the cars physics is calculated (a stretch but possible)

oh
lastposes is last position seatpart
self.DataStorage.Main.AddPose.Value is Vector3Value
изображение

Camera Update in other module script

game:GetService("RunService"):BindToRenderStep('CameraMovementEvent',Enum.RenderPriority.Camera.Value,function()
         game.Workspace.CurrentCamera.CFrame += self.DataStorage.Main.AddPose.Value
end)


Camera work correctly (i disabled script with change value and changed myself)

Ok my last piece of advice is to also make sure the calculations are bound to PreRender aswell, as task functions are called after rendering, so to test it try something like this:

--psuedocode
game:GetService("RunService"):BindToRenderStep('CameraMovementEvent',Enum.RenderPriority.Camera.Value,function()
	 local calcu = self.plrdata.hum.SeatPart.Position-lastposes
     self.DataStorage.Main.AddPose.Value = calcu 
     lastposes = self.plrdata.hum.SeatPart.Position
     game.Workspace.CurrentCamera.CFrame += self.DataStorage.Main.AddPose.Value
end)

heres a little chart i found on roblox’s documentation to show how roblox steps through frames, and its important that all camera manipulations happen before the screen drawing

Hope this helps! :grin:


still too same

Of course it is laggy bro, you’re running this code in a literal while loop that only runs every 0.1 seconds. This is also extremely unoptimized and your variables are not named well. Put the camera calculations in a Heartbeat Loop, or just make your camera first person.

He already switched to using :BindToRenderStep

I’m fixed, just getting AssemblyLinearVelocity and it work as needed, without twitches.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.