Camera Shaking when changing cframe

I have a custom shiftlock script that changes the cameres position, when the offset value is changed to 1.75 the camera begins to shake violently the lower the clients fps, is there any way to fix this

game:GetService("RunService"):BindToRenderStep("CameraOffset", Enum.RenderPriority.Camera.Value - 1, function(delta)
	if plr.Character then
		currentCamera = workspace.CurrentCamera
		currentCamera.CameraSubject = plr.Character.Head
		local offset = Vector3.new(1.75, 0, 0)
		TS:Create(currentCamera, TweenInfo.new(.1), {CFrame = currentCamera.CFrame * CFrame.new(offset)}):Play()
	end
end)
1 Like

Tweens in a RunService?? You must be joking.

Tweens have a set time/duration to play which you can specify which in this case is 0.1, but the RenderStepped runs every tick. Meaning before the tween can finish, it’s going to start playing again, causing jittering.

Just use the code I provided in your other post. Be sure to change the offset to your liking:

local plr = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera

game:GetService("RunService"):BindToRenderStep("CameraOffset", Enum.RenderPriority.Camera.Value - 1, function()
	if plr.Character then
		
		plr.Character.Humanoid.AutoRotate = false
		
		local offset = Vector3.new(1, 0, 0)
		
		plr.Character.Humanoid.CameraOffset = offset
			local currentCFrame = plr.Character.PrimaryPart.CFrame
			local targetCFrame = CFrame.new(plr.Character.PrimaryPart.CFrame.p, plr.Character.PrimaryPart.CFrame.p + Vector3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
		local newRotation = currentCFrame:Lerp(targetCFrame, 10 * game:GetService("RunService").RenderStepped:Wait())
		plr.Character.PrimaryPart.CFrame = CFrame.new(plr.Character.PrimaryPart.Position, newRotation.p + newRotation.LookVector)
	end
end)
1 Like

Im trying to to use camera offset and manually change the cameras position because it provides better results for my game

1 Like

Have you not read my code, it literally uses camera offset?? In addition, this is the code YOU provided in the other post for us to edit??

1 Like

when I use this the cameras position does not change at all

currentCamera.CFrame = currentCamera.CFrame * CFrame.new(offset)
1 Like

There is a property in Humanoids called CameraOffset, which is a Vector3 value. You can use this property to achieve the same sort of effects that you’re wanting to do. Documentation

2 Likes

No I just changed the approach to not using the humanoid camera offset, sorry for miscommunication

1 Like

It doesn’t because the CameraType is not set to scriptable. If you change it to scriptable it will start working.

1 Like

Why not? It’s so much easier using CameraOffset, especially for systems like these. It will save you a ton of time.

1 Like