- Home /
using Mathf to find the inverse tan in degrees
I am using 2 raycasts to find the difference in terrain height , and then rotating my object to match the terrain angle between the 2 raycasts. But Mathf.Atan seems to be returning the wrong value. Sample of script :
// calculate Z angle
differenceYZ = vectorBoardFront.y - vectorBoardBack.y;
angleBoardZtan = differenceYZ / widthRaycastZ;
angleBoardRotX = Mathf.Atan(angleBoardZtan);
// rotate board to align to terrain (Z angle is on the X-axis, and vice verca)
transform.rotation = Quaternion.Euler (angleBoardRotX, 0, angleBoardRotZ);
How do I find in degrees : angle = tan-1 (Oo/Aa) ?
Answer by Kryptos · Mar 21, 2012 at 04:40 PM
All Mathf angle methods work with radians. You need to convert the result to degrees.
angleBoardRotX = Mathf.Rad2Deg*Mathf.Atan(angleBoardZtan);
That has fixed my angle , thankyou very much . I have never understood radians, so this is a great quick fix. Now I can carry on :)
Don't forget to mark this questions as resolved by selecting this answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065400im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SmoothDamp from 360 to 1 1 Answer
Mathf.Atan changes instantly even with a slow lerped value 1 Answer
[Math] Why is this possible ? 1 Answer
How to store direction so that player faces last direction when joystick is idle 2 Answers
Measuring the Angle Between Two Transforms for t Param of Quaternion.Slerp 1 Answer