Question by 
               dudonak · Nov 04, 2021 at 03:14 PM · 
                rotationrotaterotate objecteulerangles  
              
 
              Rotation Issue
Im trying to make when my character jumps he tilts his body 20 degrees back and when he is falling he tilts 20 degrees to front.
I made a script which is turning the player to back when he is jumping and checks if he is turned less than 20 degrees but when i put negative number as x rotation the script don't work and the player can turn backwards forever. Turning forward when i fall works perfectly as i put the positive number as x rotation.
Where can the issue be?
 if (jump == true && gameObject.transform.eulerAngles.x > -20)    
     gameObject.transform.Rotate(-5, 0, 0);
 else if (jump == false && gameObject.transform.eulerAngles.x < 20)
     gameObject.transform.Rotate(5, 0, 0);
 
              
               Comment
              
 
               
              Consider this.
 Vector3 velocity = positionLastFrame - transform.position;
 Vector3 eulerTarget = transform.eulerAngles;
 
 if( velocity.y==0 ) eulerTarget.x = 0f;
 else if( velocity.y<0 ) eulerTarget.x = -20f;
 else eulerTarget.x = 20f;
 
 transform.rotation = Quaternion.Lerp( transform.rotation , Quaternion.Euler(eulerTarget) , Time.deltaTime*2f );
 
                 Your answer