Camera Keep Shaking while using CFrame.LookAt

Hi There,I was going to make a camera focus system for a PvP game,but the camera keep shaking when the camera focus system working,i dont know how does the bug happen.

Here’s the Code:

runservice.RenderStepped:Connect(function()
	local pos = player.Character:WaitForChild("HumanoidRootPart").CFrame:ToWorldSpace(CFrame.new(3,3,3)).Position
		if cameralock == true then
	local cam = workspace.CurrentCamera
		cam.CFrame = CFrame.lookAt( pos,game.Workspace.Part.Position)
		player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(player.Character.HumanoidRootPart.Position,game.Workspace.Part.Position)
		end
		end)


1 Like

Hey so if you are going to make a custom camera system, make sure you set the Camera’s CameraType property to Scriptable, otherwise the default Roblox scripts will still try and control the camera, leading to the shaking you are having problems with.

When the physics updates, since the script tilts the root around its relative x-axis it becomes unstable and the character itself shakes. The camera shakes probably because of how its own CFrame updates are done relative to the root’s CFrame updates.

runservice=game:GetService("RunService")
player=game.Players.LocalPlayer
cameralock=true
cam=workspace.CurrentCamera

repeat wait() until player.Character~=nil
local root=player.Character.HumanoidRootPart

local prevPos = root.CFrame
runservice.Heartbeat:Connect(function()
	local currPos = root.CFrame
	if currPos ~= prevPos then
		prevPos = currPos
		root.CFrame = CFrame.lookAt(root.Position,Vector3.new(game.Workspace.Part.Position.X,root.Position.Y,game.Workspace.Part.Position.Z))

	end
end)

runservice.RenderStepped:Connect(function()
	cam.CameraType=Enum.CameraType.Scriptable
	local pos = root.CFrame:ToWorldSpace(CFrame.new(3,3,3)).Position
	if cameralock == true then
		
		cam.CFrame = CFrame.lookAt( pos,game.Workspace.Part.Position)
	end
end)

Something like this might work. The Heartbeat updates the root CFrame separately only as the player moves it, and has it only spin on the y-axis.

1 Like

Thanks for helping,but seems like the bug isnt because of the priority of camera,when i added a line of script that is:

''lua
cam.CameraType = Enum.CameraType.Scriptable
"

Nothing helps,but still thanks!

Thank u!This helped me slove the problem,now i totally understood what to do,Thanks again!

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