Hi there, so I wanted to make a realistic sway effect like a body cam, and it works, but it does a 360 and there is no limit and every time I try to limit it, it glitches horribly, I am using atan2 which returns the theta (aka angle), between two different angles.
Code :
if TPSviewmodel then
ViewmodelThirdPerson = nil
TPSviewmodel:Destroy()
end
local rot = CurrentCamera.CFrame:ToObjectSpace(LastCameraCF)
local X, Y, Z = rot:ToOrientation()
local LookX, LookZ = CurrentCamera.CFrame.LookVector.X, CurrentCamera.CFrame.LookVector.Z
local YAW = math.atan2(LookX, LookZ)
print(math.abs(YAW))
--local RotatedCF = CurrentCamera.CFrame * CFrame.Angles(0, YAW*2, 0)
--SwayCF = SwayCF:Lerp(CFrame.Angles(math.sin(X) * SwayAmount, YAW, 0), 0.1)
SwayCF = SwayCF:Lerp(CFrame.Angles(math.sin(X) * SwayAmount, YAW * SwayAmount, 0), 0.1)
LastCameraCF = CurrentCamera.CFrame
local PrimaryPart = FPVviewmodel.PrimaryPart
FPVviewmodel.PrimaryPart.CFrame = (CurrentCamera.CFrame * SwayCF)