I’m using this code to rotate a cube on a button press. It’s been infuriating to get to this point but this script ended up working well. Anyways, I noticed when I press the button that rotates the cube clockwise four times, it goes from 0 to 90 to 180 to 270 but then back to a very small number that’s not exactly 0 (I think it was like 1.10017001e2 or something)
Case in point, clockwise rotation = not back to zero after four button presses. However, the same thing doesn’t occur when i rotate counterclockwise.
I can press the button four times and it goes back to zero exactly. Any idea why this might be happening?
(here’s the code)
using UnityEngine;
using System;
using System.Collections;
public class Example : MonoBehaviour {
int rotCount = 0;
bool inmotion = false;
void Update() {
if (Input.GetKeyDown("e") && !inmotion) {
rotCount = (rotCount + 1) % 4;
DoRotation();
}
if (Input.GetKeyDown("q") && !inmotion) {
rotCount = (rotCount - 1) % 4;
DoRotation();
}
}
void DoRotation() {
inmotion = true;
int rot = rotCount * 90;
iTween.RotateTo(gameObject, iTween.Hash("y",rot,"oncomplete","EndRotation","time",1.00));
}
void EndRotation() {
inmotion = false;
}
}