- Home /
iTween Rotation not exact
Hey Unitarians,
I have a cube, and I'm using iTween to rotate it. I'm not very familiar with iTween, but I managed to make it rotate 90 degrees every time I click the screen. There is one problem. When I rotate it, the rotation is off by a fraction of a degree. This adds up and the whole square becomes skewed after a while, making the game unplayable. I used this code to rotate it:
iTween.RotateBy(gameObject, iTween.Hash("z", -0.25, "easeType", "easeOutExpo", "time", 0.2, "loopType", "none", "delay", 0));
When that didn't work, I tried using RotateAdd, which got the exact same result, skewing the square by a small amount:
iTween.RotateAdd(gameObject, iTween.Hash("z", 90, "easeType", "linearTween", "time", 0.1, "loopType", "none", "delay", 0));
Because I couldn't find a solution I tried using a rounding method to center the square .025 seconds after the initial rotation animation. I used this IEnumerator:
IEnumerator RoundRotation () {
yield return new WaitForSeconds(.225f);
transform.rotation = Quaternion.Euler (transform.rotation.x, transform.rotation.y, angleOfRotation);
}
That works, except when I click really fast (faster than .225 seconds) the animation is really choppy and looks buggy even though it works (which is still not ideal). This can't happen.
I don't know what to do to ensure that the square rotates exactly 90 degrees. No more, no less. Any help would be much appreciated.
Thanks in advance, Aman Jha