Hello
So I want to rotate a circle to show different images. If I have say 21 images. Then in order to rotate the circle(a gameobject in my case) I would have to rate it 21 times to show all the images. This making each rotation in degrees in the given axis 360 / 21. However, for some reason this does not work.
If I just print out 360 / 21 then I get 17 in the console… Which is incorrect as the answer is roughly 17,14. The variable is a float and really I don’t know what to do.
If I rotate it one lap(21 times) I end up at 177 degrees(started at 180). Which is off by quite a bit.
If you do “print (360 / 21)”; this will print out an integer value and it will be 17. But if you do"print (360f / 21f)" which are floats, you get a correct float value. If you work with float numbers always put an f after them to be sure. It sometimes matter, sometimes not. Also comparing floats is not very reliable because they are somewhat inaccurate. After a lot of calculating they end up having some difference between the expected and the real value. I usually round them with Mathf.Round.
If you use
print(360 / 21f);
or
Debug.Log(360 / 21f);
you’ll see that you get 17.14286 as intended.
It’s being rounded down so if you declare your float with
floatName = 360 / 21f;
you’ll get your the desired result, I believe.