Floats are prone to rounding errors, and that is probably what you are experiencing here. Have you tried skipping the 100f parts? Shouldn’t a simple; newZ =Mathf.Round(newZ) be just as good and less likely to cause rounding errors. You could even try to cast it as an int.
first off I need to point out that rotations aren’t stored as euler angles internally. So when you set eulerAngles or read eulerAngles, a conversion is happening. The rotation is actually stored as a Quaternion which is a 4-d vector made up of complex numbers (a + bi type complex numbers). The conversion to and from quaternion to euler isn’t perfect due to float errors as well as the trigonometry involved (trig is problematic in discrete systems like a computer). So you should expects slight inaccuracies here and there.
Thing is 0.9710001 is an inaccuracy of 0.289999, which is a bit high.
And it’s not the value I’m getting on my machine.
Which makes me wonder what -angle is. What’s its value? Can you show us the full code?
Thank you for the explanation, anything I can learn from this issue is appreciated, I’m still a rookie at this point so I apologize for any seemingly obvious issues to you.
The thing that’s strange is that I am getting the same inaccuracy on a blank project, the inaccuracy is still 0.028999.
Below is the code for ‘angle’, but it is converted to an int so it shouldn’t be causing any issues I don’t think.
EDIT: The blank project consisted of a 2D sprite with a script attached that just had the following code in the start function:transform.eulerAngles = new Vector3(0,0,1);
I have found another way to achieve what I wanted using Hingepoints but if anyone can answer this question it could be useful to know in the future for something maybe