Vector3.SignedAngle not caring about axis

Hi,

I just noticed the Vector3.SignedAngle seems to not care about the axis vector argument, it worked in earlier versions. The Vector3.right gives the exact same result as Vector3.up, just with flipped signs some times, but exactly the same numerical value. It returns the same values as Vector3.Angle.

Its in Unity 2020.3.34.

This returns the same values (almost, just flipped signs sometimes, but exact same value):
Vector3.SignedAngle(currentForward, playerCameraTransform.forward, Vector3.right)
as this:
Vector3.SignedAngle(currentForward, playerCameraTransform.forward, Vector3.up)
and this:
Vector3.Angle(currentForward, playerCameraTransform.forward)

Am I missing something?

Seems highly unlikely this would change from one version to the next. I would assume Unity would have unit test for APIs like this as they’re 100% deterministic.

Have you tested this on earlier version of Unity and observed different results using the same input values?

Debug.Log($"Vector3.Angle (forward,up) = {Vector3.Angle(Vector3.forward,          Vector3.up)}");
Debug.Log($"Vector3.Angle (forward,down) = {Vector3.Angle(Vector3.forward,          Vector3.down)}");
Debug.Log($"Vector3.SignedAngle(forward,up, right) = {Vector3.SignedAngle(Vector3.forward,   Vector3.up, Vector3.right)}");
Debug.Log($"Vector3.SignedAngle(forward,down, right) = {Vector3.SignedAngle(Vector3.forward, Vector3.down, Vector3.right)}");

In Unity 2020.3.34.

Results:

Vector3.Angle (forward,down) = 90
Vector3.SignedAngle(forward,up, right) = -90
Vector3.SignedAngle(forward,down, right) = 90```

Seems correct to me. Can you provide the actual direction vectors and what you expected the result to be? _**currentForward**_ and __*playerCameraTransform.forward*__ are unknowns so no one can test your inputs.
1 Like

Yes, SignedAngle does not perform any kind of projection onto a plane that is perpendicular to the given reference axis. All it does is calculating the angle between the two given vectors. The third vector is only used to determine the sign. It has no effect on the angle value. The documentation tried to make that clear in the text.

Yeah, you are right. Have verified it with 2019, and 2020.1.12.

I used the log line in the code earlier to determine some limits for the angles in the scene. I probably just didn’t pay too much attention to them throwing out the same numbers. Just assuming the axis was the reference for the angles. The documentation wasn’t really that clear:

“axis A vector around which the other vectors are rotated.”

The currentForward is the vector from the player to the target, target.position - player.position.
I was expecting yaw values for the camera when the signedAngle was calculated with Vector3.up as a reference, and pitch values when using playerCameraTransform.right as a reference.