Setting an rotational camera offset

Hi! This is my first post and I really want to know how I could offset the player camera’s rotation (in first-person view specifically).

I tried to tackle this issue today writing this: (I’m using a module called “spring” by someone named “BlackShibe” by the way)

--This stuff runs every frame
local cam = CameraSpring:update(deltaTime)
            
local withoutOffset = Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()) - Vector3.new(currentOffset:ToEulerAnglesXYZ())
            
currentOffset = CFrame.Angles(cam.x,cam.y,cam.z)
            
Camera.CFrame = (CFrame.new(Camera.CFrame.Position)*CFrame.Angles(withoutOffset.X,withoutOffset.Y,withoutOffset.Z))*currentOffset

But the problem is it only works when looking at a certain horizontal direction.

I did look on dev-forums along with a couple google searches with the keywords along the lines of “camera orientation offset” and such. I’m asking how to do this for a gun system I am making where I would like to offset the camera orientation for things like animation, walking sway, etc. My previous attempts at doing something like this weren’t very reliable and were usually not turning out how I want.

Let me know if this is enough information and whether or not this is even possible

1 Like

I did it I solved it look guys heres the code

local cam = CameraSpring:update(deltaTime)
			
local previousFrame = Vector3.new(currentOffset:ToEulerAnglesXYZ())
local thisFrame = Vector3.new(cam.x,cam.y,cam.z)
			
local difference = thisFrame - previousFrame
			
Camera.CFrame *= CFrame.Angles(difference.X,difference.Y,difference.Z)
			
currentOffset = CFrame.Angles(cam.x,cam.y,cam.z)
3 Likes