I am working on a stealth game. Currently I am making a coroutine that allows the player to peek around corners while in cover. I am having a small problem though. The code gets to the snippet below with no issue, but when it hits the rotation part, it does a few odd things. If I rotate the player hit box by 30f * Time.deltaTime, it rotates the wrong direction into the wall and flips out, crashing the game. If I rotate the player hit box by 30, it rotates the correct way but it jumps to 30 degrees of rotation then jumps to 60 degrees, 90, etc and continues spinning. Other times, the rotation just does crazy things that I can’t replicate. I’m not sure if I am missing something huge or just don’t understand how some aspect or another works. Any help would be great. Thanks!
while(canPeek == true && count <= 30)
{
count++;
yield return null;
Debug.Log(rotDir + count);
}
if(count >= 30)
transform.Rotate(30f * Time.deltaTime, 0f, 0f);
while(canPeek == true && count >= 30)
{
if(Input.GetKeyDown("left ctrl"))
{
//switch cover to second closest
}
Debug.Log(rotDir + count);
yield return null;
}
if(count >= 30)
transform.Rotate(-30f * Time.deltaTime, 0f, 0f);