Unity transform.forward issue

When I rotate a character to say 0 deg, or 180 deg, it’s “forward” shows clearly X = 0, Z = 1/-1. However if I rotate the character to 90/-90 or 270/-270, it’s forward shows X = 1/-1, but the Z always shows “-1.192093e-07”… And I also noticed that the debug rays that calculate from the forward go every which way, mainly the one ray shoots down into the ground. I am assuming that this is because Z is not equaling zero, when my character is rotated toward the east/west position.

Is there a issue with unity’s rotation calculations? Or is there a separate trick that I must modify the Z to zero myself?

*NOTE: Using unity 5.6.3p1, which should be most recent update. This is done in the inspector, whilst game is running. So my 90 and 270 are absolute degrees, no miscalculations. And a public Vector3 = transform.forward, should be showing accurate…

Ok, so the answer is Unity uses Quaternions to justify the rotations, to avoid Gimbal Lock.

Meaning, using transform.LookAt(otherLocalPosition); should not be used.

transform.rotation = Quaternion.lookRotation(otherLocalPosition); SHOULD be used.

By using a character, you only want it’s up to stay up. Apparently LookAt will modify the characters X, and Z rotation. Which you only want the Y to rotate, so calling for the Quaternion to look at the local position does just that.

Meaning, my issue was my character was not perfectly UP, so changing the rotation degrees manually in the inspector ruined the transform.forward. One big hint was the number I received from forward had a E in it. Which i’m assuming meant there was a problem in the Euler Angles?