Slerp rotation issue when calling a lot
I've been having this issue with Slerp that I can not seem to fix. I want to have the player sprite rotate slowly when I press the left or right button. This code works. However when I start playing quickly and spam left and right quickly, weird things start to happen and the player starts glitching left and right from -90 degrees to +90 etc. How could I fix this issue while still allowing to press both left and right at the same time
Here is my code:
StartCoroutine(RotateMe(Vector3.back * 15, 0.25f));
IEnumerator RotateMe(Vector3 byAngles, float inTime)
{
var fromAngle = Player.transform.rotation;
var toAngle = Quaternion.Euler(Player.transform.eulerAngles + byAngles);
for (var t = 0f; t < 1; t += Time.deltaTime / inTime)
{
Player.transform.rotation = Quaternion.Slerp(fromAngle, toAngle, t);
yield return null;
}
}
Comment
I imagine you are stopping the coroutine before calling "rotateme"? you can use StopAllCoroutines for that