SignedAngle
Calculates the signed angle between two vectors, using a third vector to determine the sign.
Read time 3 minutesLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
SignedAngle(Vector3, Vector3, Vector3)
Calculates the signed angle between two vectors, using a third vector to determine the sign.
public static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis)
Parameters
Returns
Type | Description |
|---|---|
| float | The signed angle between |
Remarks
The angle returned is the angle of rotation from the first vector to the second inside the plane that contains both vectors. The returned angle is between -180 and 180 degrees, because the method returns the smallest angle between the vectors.
The sign of the angle is determined using the direction axis provided as the parameter. The direction is determined by whether the direction axis projects onto the positive or negative of the rotation axis. The axis of rotation is the vector perpendicular to the rotation plane. You can use the cross product to determine the axis of rotation for the two input vectors.
axisIf the direction axis points the same side of the rotation plane as the rotation axis, then the resulting angle is positive. If the direction axis points the opposite direction to the rotation axis, then the resulting angle is negative. Note that changing the order of and reverses the direction of the rotation angle.
fromtoThe following diagram shows the relationships between the input vectors and the rotation and direction axes.

The and vectors lie in the blue plane. Both the rotation axis and the direction axis point above the rotation plane, so in this case the returned angle is positive.
fromtousing UnityEngine; public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 targetDir = target.position - transform.position; Vector3 forward = transform.forward; float angle = Vector3.SignedAngle(targetDir, forward, Vector3.up); if (angle < -5.0F) print("turn right"); else if (angle > 5.0F) print("turn left"); else print("forward"); } }
Additional Resources: Vector3.Angle function.
SignedAngle(Vector3, Vector3, Vector3)
Calculates the signed angle between two vectors, using a third vector to determine the sign.
public static float SignedAngle(in Vector3 from, in Vector3 to, in Vector3 axis)
Parameters
Returns
Type | Description |
|---|---|
| float | The signed angle between |
Remarks
The angle returned is the angle of rotation from the first vector to the second inside the plane that contains both vectors. The returned angle is between -180 and 180 degrees, because the method returns the smallest angle between the vectors.
The sign of the angle is determined using the direction axis provided as the parameter. The direction is determined by whether the direction axis projects onto the positive or negative of the rotation axis. The axis of rotation is the vector perpendicular to the rotation plane. You can use the cross product to determine the axis of rotation for the two input vectors.
axisIf the direction axis points the same side of the rotation plane as the rotation axis, then the resulting angle is positive. If the direction axis points the opposite direction to the rotation axis, then the resulting angle is negative. Note that changing the order of and reverses the direction of the rotation angle.
fromtoThe following diagram shows the relationships between the input vectors and the rotation and direction axes.

The and vectors lie in the blue plane. Both the rotation axis and the direction axis point above the rotation plane, so in this case the returned angle is positive.
fromtousing UnityEngine; public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 targetDir = target.position - transform.position; Vector3 forward = transform.forward; float angle = Vector3.SignedAngle(targetDir, forward, Vector3.up); if (angle < -5.0F) print("turn right"); else if (angle > 5.0F) print("turn left"); else print("forward"); } }
Additional Resources: Vector3.Angle function.