Hello again. I’ve made a cube that begins the game rotating on the middle of the screen. Upon any key click, the camera zooms forward, and the cube Lerp rotates to a quaternion.identity. My problem is that the value continuously approaches 0 (or 360), and once it comes very close to those values, the X, Y, and Z rotation coordinates start jumping up to values <10 and continuously fluctuate.
I am trying to get the cube to reach a specific rotation, then release control of the cube, so it can then be interacted with a rotated by player Input. I have an extra script that will set rotation to Quaternion.identity after hitting Spacebar, but trying to rotate the cube later via player input is thwarted and and the cube keeps Lerping towards 0,0,0.
I’m very new to Unity still; any help is greatly appreciated!
public bool rotateCube = true;
public GameObject myDestination;
public float zoomSpeed = 2.0f;
public float rotSpeed = 2.0f;
public Quaternion originalRotation;
public Quaternion prevRotation;
public int curFacing;
private bool keepSpinning;
void Awake ()
{
originalRotation = transform.rotation; //setting base value to spin to later!
}
// Update is called once per frame
void Update ()
{
if (rotateCube) //designates if rotateCube = true, continue.
{
KeyPressedNoSpin();
}
else if (!rotateCube)
{
CameraZoom();
CubeSpin();
CubeControls();
}
}
//CALLED SCRIPTS BELOW
void KeyPressedNoSpin() //key press stops initial spin and sets "facing" to 0 (front!)
{
transform.Rotate(new Vector3(30, 30, 10) * Time.deltaTime);
if(Input.anyKeyDown)
{
Debug.Log("Any Key has been pressed");
rotateCube = false;
Debug.Log ("Current Cube Face is Front");
curFacing = 0;
}
}
void CameraZoom()
{
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, myDestination.transform.position, zoomSpeed * Time.deltaTime); //zoom camera
}
void CubeSpin()
{
transform.rotation = Quaternion.Lerp(transform.rotation, originalRotation, Time.deltaTime * rotSpeed); //cube returns to basic position!!
if(Input.GetKeyDown(KeyCode.Space)) //failsafe to stop rotating
{
transform.rotation = Quaternion.identity;
}