Vector3.SignedAngle wrong direction when crossing the 0 point

Hi,

I’m using the Vector3.SignedAngle to determine the rotation direction of a steeringwheel.

All working fine until the steeringwheel crosses the 0 degrees point(up direction of steeringwheel).
When it crosses the 0 point it gives the opposite rotation direction once.
I suppose it has to do with the fact that the “prevRotationDegrees” is on the other side of the 0 point.

Is there a solution for this?

This is my implementation:

Vector3 currentRotationVector = transform.localRotation.eulerAngles;
			float angle = SignedAngle(prevRotationVector, currentRotationVector, Vector3.up);
			if (angle < -30.0F)
			{
				print("turn left");
				prevRotationVector = currentRotationVector;
			}
			else if (angle > 30.0F)
			{
				print("turn right");
				prevRotationVector = currentRotationVector;
			}

Good day.

I understand, that when the result is 30º but is at the other side of 0, you recieve a -30º , right? And you just want the 30? Or what?

Well anywhay, I think if you are smart by using the Mathf.Abs() you can get what you need.

Abs (from absolute) so Abs(-30) = 30 and Abs30(30) = 30. Does not care the direction, you get the positive. This way you can “control” the angle number to do what you need.

The other way is to detect if the result will be positive or negative before calculating, and make the needed correction to get the desired result.

Bye!