Euler angles are terrible. If you use them at all, they absolutely must be write only, or you will get side effects like this (the linked article goes into more detail).
Use Quaternion’s other functions, like Quaternion.AngleAxis for this case. Something along these lines:
Your original code would have had the same problem, had it completed a circle - it’s an attribute of the t < duration logic. If it’s important to end on the exact 360-degree rotation after everything else, you need to put a line after the loop that sets that.
private IEnumerator Rotate(
float in_deltatime,
int id,
float duration,
EInputState in_secondState)
{
Vector3 rot = _players[id].transform.rotation.eulerAngles;
float endRotation = rot.x + 360.0f;
float t = 0.0f;
while ( t < duration )
{
if ( _stopRotation[id] == true )
{
yield break;
}
t += in_deltatime / duration;
float angle = Mathf.Lerp(rot.x,endRotation,t);
Vector3 fixedRot = new Vector3 (-angle,rot.y,rot.z );
_players[id].transform.rotation = Quaternion.Euler( fixedRot );
yield return null;
}
}
But sometime after the loop is going to jump from -180 to 140 or something like that, is for the same issue? I have to set the position after the loop?