How to offset camera orientation while locked in first person without rotating character

I want to be able to offset the camera’s rotation without rotating the character model for a recoil and leaning script. I still want the character model and camera to rotate by moving your mouse, however, I don’t want to update the character’s orientation with the camera offset. The issue is that the camera spins because the character rotates after I update the camera’s y orientation which then updates the next frame repeating the cycle. I have tried to look for other solutions on the creator hub but none of the solutions worked/were unrelated.

		local recoil = RecoilSpring:update(delta)
		local lean = LeanSpring:update(delta)
		local cam = CameraSpring:update(delta)
		
		--hum.AutoRotate = false
		camera.CFrame = Head.CFrame
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
		Arms.FakeCamera.CFrame = camera.CFrame * CFrame.Angles(0,0,lean.Z)
		Arms.FakeCamera.CFrame *= CFrame.new(0,recoil.Y * 2,recoil.Z)
		Arms.FakeCamera.CFrame *= CFrame.Angles(recoil.X, 0, 0)
		camera.CFrame *= CFrame.Angles(recoil.X, 0, 0)
		
		hum.CameraOffset = -camera.CFrame.RightVector * lean.Z*3

Could you try disabling Autorotate of the Humanoid?

I still want the character to be able to rotate with the camera just to not update with the offset.

You can use alignorientation then i guess

That would still have the same issue since the camera’s CFrame gets set to the Head’s CFrame, there may be a way to not set the CFrame to the head then offset but I’m not sure.

You can bind functions to RenderSteps with RunService:BindToRenderStep(). This allows you to offset the camera just before the next frame is rendered and then set the camera’s cframe back to the normal one before Input Priority so that it doesn’t affect the characters input/normal camera movements/character cframes etc.
Quick Example:

local Camera = workspace.Camera
local runservice = game:GetService("RunService")

local PrevCF = Camera.CFrame--stores the default camera CFrame with no offset, it'll get updated later anyway
function OffsetCamera(dt)
	PrevCF = Camera.CFrame--stores it again before aplying offset

	--Offsetting the camera with a LOT of rotation
	local AngleDegreeSize = 50
	local Offset = (math.sin(time()*math.pi)*AngleDegreeSize)/2

	local AngleOffset = CFrame.Angles(0,math.rad(Offset),0)
	Camera.CFrame = PrevCF*AngleOffset--Applies the offset to the camera
end


function BeforeInput()
	--Resets the camera back to normal so that it is used in the input priority as if there was no offset at all
	Camera.CFrame = PrevCF
end
--Binding those functions to their corresponding priorities
--Last.Value is before next frame
--Input.Value-1 is before input processing
runservice:BindToRenderStep("OffsetCamera",Enum.RenderPriority.Last.Value,OffsetCamera)
runservice:BindToRenderStep("BeforeInput",Enum.RenderPriority.Input.Value-1,BeforeInput)

If you do want the offset to affect the character’s movement/input you could change from Input priority to Camera priority.

1 Like

Thank you so much, this worked!

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