Using rotation values past 180 degrees?

Hi, I’ve written a little script for controlling an object like a jetpack. I also wrote some script for righting the player so that they’re not constantly fighting to stay in control. However, whenever the object rotates past 180 degrees (even if they rotate like a top), the self righting code freaks out.
Example of rotational script:

if(Input.GetKey("w"))
	{
		playerObj.transform.Rotate(Vector3.right * (rotationSpeed*Time.deltaTime));
		//print("forward rotation");
	}

Example of self righting script:

if(Input.GetKey("w") == false  playerObj.transform.rotation.x > 0) 
	{
		playerObj.transform.Rotate(Vector3.right * (-resetSpeed*Time.deltaTime));
		//print ("reset forward x rotation");
	}

It’s weird because if you rotate past 180 degrees on the Y axis, the code that only checks the X axis is activated for some reason.

I’d appreciate any help, this has been bugging me for a while.

This:

Input.GetKey("w") == false  playerObj.transform.rotation.x > 0

Doesn’t do what (I’m guessing) you think it does. ‘rotation’ is a quaternion; although the value of rotation.x does have a meaning, I wouldn’t rely on it for something like this. (For one thing, q and -q represent the same rotation, so whether x is > 0 or < 0 in this particular case could be arbitrary.)

Maybe what you’re wanting is Transform.eulerAngles or Transform.localEulerAngles. However, I wouldn’t recommend using either of those for this either. If you want to use something like your current method, you could determine how the player is oriented by measuring the angle of the forward vector relative to the ground plane (or even just checking the y value). Another approach that often works well for this sort of thing is to apply a corrective rotation over time that rotates the local up vector onto the world up vector (which the method you’re using will do as well, more or less, but the ‘shortest arc’ rotation method is a bit more general).