Help with math.asin in head movement relative to camera script

So I get that math.asin is 1/math.sin and how this shows graphically in this post, but in this youtube video, it uses this script:

local camera = workspace.CurrentCamera

local character = game.Players.LocalPlayer.Character
local root = character:WaitForChild("HumanoidRootPart")
local neck = character:FindFirstChild("Neck", true)
local yOffset = neck.C0.Y

local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

game:GetService("RunService").RenderStepped:Connect(function()
	local cameraDirection = root.CFrame:toObjectSpace(camera.CFrame).lookVector
	
	if neck then
		neck.C0 = CFNew(0 , yOffset, 0) * CFAng(0, -asin(cameraDirection.x), 0) * CFAng(asin(cameraDirection.y), 0, 0)
	end
end)

to make headmovement with motor6D and math.asin. I don’t get how math.asin (1/math.sin) is used to accomplish this goal or really how it works in this situation. Someone explain please? Thanks for your time

Edit: I have also looked at some khan academy vids but i still cannot make sense of it

1 Like

Not really great at math but I’ll try to explain it the best I can

  • We get the arc sine of the camera lookvector relative to our HumanoidRootPart
  • Arc sine returns a value between -pi/2 and pi/2 based on how much does the camera lookvector differ from the rootpart lookvector
  • We use this value in CFrame.Angles, and CFrame.Angles takes values in radians
  • If you convert -pi/2 and pi/2 from radians to degrees it’ll give us an almost perfect range between -90 and 90 degrees of rotation

Edit : Made it easier to read

1 Like

Thanks! (for my own curiosity) is there any way to prove this behaviour of arc sin?

Yep!
You can print out the value of cameraDirection, take either x (vertical rotation) or y (horizontal rotation) at any point in time, manually use either -math.asin on x or just math.asin y and convert the returned value from radians to degrees, the results should be consistent.