I've a player (a space-ship ;) that can rotate from -x to +x value (so clamped). So, before apply rtoation i check it:

// Got Horizontal Input 
    h = Input.GetAxis("Horizontal");

// In next code line: I want to take CURRENT x rotation , but if i use
// eulerangles.x i got eulerAngle (from 0 to 360) and it not work for my job 
// angleRotX = Player.transform.rotation.eulerAngles.x;

angleRotX += h;
angleRotX = Mathf.Clamp(angleRotX, MinEulerAngleRotX, MaxEulerAngleRotX);
// Apply new rotation: 
Player.transform.localEulerAngles = new Vector3(angleRotX, angleRotY, angleRotZ); 

Can you help me solve it ?


  • 1
    \$\begingroup\$ Your approach of storing your own rotation angles seems like it should work. How does the behaviour of this code differ from what you want? \$\endgroup\$
    – DMGregory
    Commented Oct 28, 2021 at 12:12
  • 1
    \$\begingroup\$ We also have past Q &A about limiting Euler angles in Unity — how have you tried applying past answers to solve your problem so far? \$\endgroup\$
    – DMGregory
    Commented Oct 28, 2021 at 12:22


You must log in to answer this question.

Browse other questions tagged .