- Home /
problem with mathf.tan
can i calculate the angle with its tangent in a java script?
Answer by Cyclops · Apr 04, 2010 at 04:37 PM
It's fairly simple: Mathf.Tan(angle).
print (Mathf.Tan(0.5));
Note that the angle must be Radians, so if you have a value in Degrees, you need to convert, like this:
var deg = 45;
var rad = deg * Mathf.PI / 180;
print (Mathf.Tan(rad));
Thank you. I was doing the opposite and calculating the angle in degrees when it was already in degrees. That's why it wasn't working.
Answer by duck · Apr 04, 2010 at 04:36 PM
Yes, you should find that Mathf.Tan works as expected. Be careful that you have capitalised it properly, and remember that the angles are given in radians for the maths functions.
If you're having a particular problem, please give more detail.
Unity also has some helper math functions to convert to and from radians, here: http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=mathf+deg+rad
@Duck, I didn't know about those - and that's why you're preparing to ascend to become a Unity Demigod. :)