- Home /
Question by
ralozkolya · Aug 01, 2012 at 12:40 PM ·
rotationtransformrotate
Rotation Angle not precise
Hello! So I want to rotate an object by fixed angle on a key press. I'm using this code:
function Update () {
if (Input.GetKeyDown("right"))
{
transform.RotateAround (transform.position, transform.forward, -15);
}
if (Input.GetKeyDown("left"))
{
transform.RotateAround (transform.position, transform.forward, 15);
}
}
So after several keypresses I get this Angle:
Any suggestions, why I get this "almost" 75 degrees?
P. S. Rotation direction doesn't change anything
untitled.png
(5.6 kB)
Comment
Unity uses floating points - floating points are not accurate and do things like that all the time.
Best Answer
Answer by Paulius-Liekis · Aug 01, 2012 at 01:45 PM
Floating point precision
Paulius Liekis, whydoidoit, thanks! So it can't be fixed anyhow?
Not really, you could $$anonymous$$athf.RoundToInt() but no guarantees even then.