Issue:
I cant seem to fix the problem, I tried asking other roblox developers for help but they did not seem to know the answer.
Code:
local LastCameraCF = game.Workspace.CurrentCamera.CFrame
local SwayOffset = game.Workspace.CurrentCamera.CFrame
local SwayAmount = .5
local Delta = .2
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(LastCameraCF)
local x,y,z = rotation:ToOrientation()
SwayOffset = SwayOffset:Lerp(CFrame.Angles(math.sin(x)*SwayAmount,math.sin(y)*SwayAmount,0), Delta)
WeaponClone:SetPrimaryPartCFrame(WeaponClone.PrimaryPart.CFrame * SwayOffset)
LastCameraCF = workspace.CurrentCamera.CFrame
Things to note:
I noticed if I disabled the lerp it started in the correct place, however If i do that the sway is not smooth.
I also attempted to fix it by using the arms and gun CFrame relative to the camera but that did not seem to work.
I also tried to set the arm positions before calling that lerp and even then it still did the lerp off screen.
Any help would be nice.
Thanks!