You don’t need 2 sides to complete the Sin or Arc Sin function. If you have a scientific calculator, you can try this out for yourself. Basically what the code is doing is it’s getting the direction of the camera, this will determine what angle the head will point at with respect to the camera’s direction in terms of radians/degrees. A vector direction can range from -1 to 1, this also applies to the trigonometric identities which you can check out here:
If you don’t have a scientific calculator or a calculator that supports the 6 trigonometric functions, you can try it out here:
I think sine requires what you’ve mentioned , but this is asin,
it returns the arc sine of x, the arc sine is of only one value, it would be the inverse sine of x when x is lower than 1 and greater than -1,
for example : sin(arcsin x) = x , as in this case the inverse of sine can be defined as arcsine.
Basically the inverse function of the sine of x if y is the sine of x means x is the arcsin of y, so you would only need one value .
As the other replies mention, math.asin takes only one argument. But you are right that it represents the inverse sine and thus that this single argument represents the ratio of the opposite and diagonal side lengths of a right (90 degree cornered) triangle.
Sin (angle) = opposite/diagonal
Asin(opposite/diagonal) = angle
However, note that in this case, the cameradirection variable holds a lookvector. A lookvector by definition is length one. So yes, technically it would be:
But since the latter magnitude is always 1 it may be omitted. I hope this helps alleviate the confusion, it’s indeed a bit tricky!
The 3 trigonomtric functions (sin, cos and tan) take an angle as an input, and output a value describing the ratio between two sides of the triangle, depending on what function you’re using.
asin, acos and atan, where the a stands for arc (arc sine), or also called the inverse trigonometric functions, mathematically denoted as sin⁻¹, cos⁻¹ and tan⁻¹, are basically the inverse of the trigonometric functions:
the trigonometric functions take an angle an the input, and ouput the ratio
the inverse trigonometric functions take the ratio as the input, and ouput the angle
Note that math.sin and others take the angle in radians not in degrees, that’s why we have to convert it to radians. And math.asin and others return the angle in radians as well, so we have to convert it to degrees.
math.sin and others are mainly used when you know the length of the angle and the length of one of the two sides that form the ratio correspondant to the used function, which satisfies this phrase (if the function was sin for example): opposite = sin(angle)*hypotenuse.
math.asin and others are used when you know two sides, and want to find the angle.
Like in your case, and I’m not sure about the math behind what you’re doing, but it’s just math.asin(cameraDirection.x) and not math.asin(cameraDirection.x/something) because it’s actually cameraDirection.x/1 and that 1 doesn’t really add much, it’s 1 because there is stuff going on with direction so it’s probably a unitvector that acts as the hypotenuse hence it’s just one. This does almost the same thing you’re doing, check it out to see more how to use math.asin.
Math.sin requires opp/hyd, math.asin figures out the theta. I.e figuring out HOW MUCH we need to rotate.
The best explanation between the relation of sin and asin, respectively the other trigonometric functions, is that we use sin to figure out lengths of unknown vectors, but with inverse trigonometric functions, we find out unknown angles.
Sin theta = opp/hyd = 0.5
theta = asin .5 --> 30º (in radians)
In depth calculation: 180º = pi * radians; 1 radians = 180/pi. We know that asin(.5) is pi/6 SO
to convert radians to degrees we do 180/pi * pi/6 --> 180pi/6pi (you can now cross out pi.) 180/6 = 30
Now, when we understand that a bit more in-depth on how the trigonometric functions relate. We take a look at cameraDirection. With CFrame:ToOBjectSpace, we draw a vector from the root to the camera and then we get the facing direction when we do .lookVector, we make are essentially just drawing an infinite Vector in the direction the camera is facing.
CameraDirection is now in trigonometric terms opp/hyd! So when we do asin(cameraDirection) it is the same as theta = asin(opposite/hypotenuse)