Can someone explain this script to me? (math.sin)

Hey devs,

I was recently given this first-person shooter script that applies a sway effect to the viewmodel, but I’m not too sure how it works. I added comments to the script to explain what I understand and what I don’t

local rotation = workspace.CurrentCamera.CFrame:ToObjectSpace(lastCamCFrame)
local X, Y, Z = rotation:ToOrientation() -- I know what this does
swayCFrame = swayCFrame:Lerp(CFrame.Angles(math.sin(X) * 0.7, math.sin(Y) * 0.7, 0), 0.1) -- I know how :Lerp() works
lastCamCFrame = workspace.CurrentCamera.CFrame -- I understand this
viewmodel.CamPart.CFrame = workspace.CurrentCamera.CFrame * swayCFrame -- I understand this

I basically just don’t understand the third line, and mainly the math.sin part, as I can’t seem to figure out how that works.

This function mostly used in trigonometry; there are two functions sine and cosine, sine is the position of Y axis on a circle, cosine is the position of X axis on a circle, e.g:

local Y = math.sin(math.rad(30)) -- we need to convert degrees to radians
local Studs = 10 -- Distance from the center point
print(Y * Studs) -- This is the position of the Y axis

About trigonometry

actually you don’t need to know what trigonometry is , in this scenario, all it’s doing is manipulating the sine wave to create a curve-like motion, they applied a multiplier of 0.7 to change the size of the swing.

the first line fetches the rotational changes based on the last camera cframe.