I have a cube and I’m trying to rotate it to specific 90 degree angles.
The camera is facing the cube so that only one side is seen, and the arrow keys are intended to rotate the cube exactly 90 degrees in any direction to see the other sides of the cube. While I can get it to rotate easily, the problem lies in trying to slow down the rotation so that the user can perceive it.
I tried using iTween, and it seemed to work but the rotations were often not to exact degrees (89.901, 269.88, etc.), and soon enough more than one side was perceptible to the user. I read that gravity effects could influence it, but my object has no rigidbody component.
Any help would be greatly appreciated
Current Code
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
public GameObject objectToRotate;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.UpArrow)) {
iTween.RotateAdd(objectToRotate, iTween.Hash("x", 90, "loopType", "none", "space", Space.World));
}
if (Input.GetKeyDown (KeyCode.DownArrow)) {
iTween.RotateAdd(objectToRotate, iTween.Hash("x", -90, "loopType", "none", "space", Space.World));
}
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
iTween.RotateAdd(objectToRotate, iTween.Hash("y", 90, "loopType", "none", "space", Space.World));
}
if (Input.GetKeyDown (KeyCode.RightArrow)) {
iTween.RotateAdd(objectToRotate, iTween.Hash("y", -90, "loopType", "none", "space", Space.World));
}
}
}