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) ?
All Mathf angle methods work with radians. You need to convert the result to degrees.
angleBoardRotX = Mathf.Rad2Deg*Mathf.Atan(angleBoardZtan);