Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to read angels greater than 360 and less than 0

Discussion in 'Scripting' started by ForgottenOne, Jun 9, 2014.

  1. ForgottenOne

    ForgottenOne

    Joined:
    May 31, 2014
    Posts:
    2
    hello Unity Community,

    I am working on a game where my player in on a hoverboard and "leans" into his turns, but I am also making his rotation equal to the normal of the surface he is on. Euler angles only go from 0 degrees to 360 degrees. For my code to work I need to be able to see relative angles .

    The reason for this problem is that when the crossover happens ( 360 to 0) it causes some grief in conditions for my leaning. Is there a way to view angles as relative?

    for example can I say:

    maxleanangle + or - contacts[0].normal?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    if(angle > 180) angle -= 360;

    will give you angles in range -180/180
     
  3. ForgottenOne

    ForgottenOne

    Joined:
    May 31, 2014
    Posts:
    2

    thank you very much!
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Generic Vector3.Angle only gives you between 0 and 180.

    You will need to do a Vector3.Dot to get if the object is on the left or right of the current object.


    Code (csharp):
    1.  
    2. angle = Vector3.Dot(Vector3.right, transform.InverseTransformPoint(target.position)) < 0 ? -angle : angle;
    3.  
    or something like that.