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.
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.