I am trying to create a camera system akin to the DSi/3DS version of Persona or Demon Gaze for the PS Vita. The problem is when I rotate the camera, it snaps to the end rotation immediately rather than over time (there’s an empty game object with this script and a character controller attached with the camera as the child). The debug.log spits out that the timeProgressed variable is still counting upwards after it rotates 90 degrees (it’s still less than one) but it’s like Slerp/Lerp (tried both) ignores it.
private float rotation;
private Transform to;
private Transform from;
public float rotateSpeed;
void Update () {
ControlPlayer();
}
void ControlPlayer(){
from = transform;
if(cInput.GetKeyDown("Left")){
rotation -= 90.0f;
to.rotation = Quaternion.Euler(0, rotation, 0);
StartCoroutine(SlerpRot(from, to, rotateSpeed));
}
if(cInput.GetKeyDown("Right")){
rotation += 90.0f;
to.rotation = Quaternion.Euler(0, rotation, 0);
StartCoroutine(SlerpRot(from, to, rotateSpeed));
}
}
IEnumerator SlerpRot(Transform startRot, Transform endRot, float slerpTime){
float startTime = Time.time;
float endTime = startTime + slerpTime;
while(Time.time < endTime)
{
float timeProgressed = (Time.time - startTime) / slerpTime;
Debug.Log(timeProgressed);
transform.rotation = Quaternion.Slerp(startRot.rotation, endRot.rotation, timeProgressed);
yield return new WaitForEndOfFrame();
}
}
}