Search Unity

Vector2.SignedAngle

Discussion in 'Documentation' started by Baste, Dec 1, 2017.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    The documentation on this function is... confusing.

    There's two problems:
    1) "The angle returned is the signed acute clockwise angle between the two vectors. This means the smaller of the two possible angles between the two vectors is used. The result is never greater than 180 degrees or smaller than -180 degrees.

    Last I checked, "acute" angle means "less than 90 degrees". It might be that I've missed something, but your definition seems mutually exclusive? Unless what you're trying to do is to make up the term "signed acute", and then define it in the second sentence. Which is a mess.

    This would be a lot easier to read as a shorter explanation with examples:
    "The angle returned is the signed clockwise angle between the two vectors. The result is never greater than 180 degrees or smaller than -180 degrees.
    Example:
    print(Vector2.SignedAngle(new Vector2(0, 1), new Vector2(0, 1)); //prints "90"
    print(Vector2.SignedAngle(new Vector2(1, 1), new Vector2(0, -1)); //prints "-135"
    "

    2) Either the implementation is wrong, or the documentation is wrong. The documentation states that these are clockwise angles. But:
    Code (csharp):
    1. Vector2.SignedAngle(Vector2.up, Vector2.right); //gives -90
    2. Vector2.SignedAngle(Vector2.up, Vector2.left); //gives 90
    Which means that looking at the vectors from the standard 2D camera, the angles given are counterclockwise.
    I kinda get what's happening; Vector2.SignedAngle corresponds to Vector3.SignedAngle with the up-axis defined as Vector3.forward. Which is... a definition, sure. But that's not a clockwise angle! Unless I'm completely missing something, which might be the case.
     
  2. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    I'm somewhat new to Unity. Just noticed #2. Docs appear to be wrong.
     
  3. etzl

    etzl

    Joined:
    Jun 22, 2018
    Posts:
    9
    seems it is calculating from the second vector to the first vector that is the correct answer with clockwise angle
     
    Sab_Rango likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    @jo-unity, somebody just posted about this. Any chance to get a confirmation from someone on what's supposed to be happening here? The documentation isn't very rigid, and by the intuitive definition, the implementation and documentation doesn't match.

    In laymans terms, the current implementation gives that the angle from 12 o' clock to 3 o' clock is -90, if the clock is a normal 2D sprite facing the camera.
     
  5. blackbrosg

    blackbrosg

    Joined:
    Apr 9, 2018
    Posts:
    20
    i can't fix this error in unity 5.6
    Assets/MCR Creator/Assets/Scripts/car/CarAI.cs(115,28): error CS0117: `UnityEngine.Vector2' does not contain a definition for `SignedAngle'

    can u help me? thanks