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

Help can't get positive/negative value from angle :)

Discussion in 'Scripting' started by cepoimario, Jun 23, 2014.

  1. cepoimario

    cepoimario

    Joined:
    May 2, 2014
    Posts:
    5
    Well i have my player GameObject and camera GameObject
    now i calculate the distance between them
    Code (JavaScript):
    1.  
    2. var rotationObject : GameObject;
    3. var player :GameObject;
    4. var angle : float;
    5. function PlayerRotation(){
    6.    angle = player.transform.eulerAngles.y - rotationObject.transform.eulerAngles.y;
    7.  
    8. }
    ok what i want to know now is the direction Negative and Positive
    Example : instead of a value from 0-360 i want :
    positive 0-180 negative 0-180
    Concept Example :
    i need the values for the Animator to know which direction to turn
    when value +50 max Animation Is idle_RightTurn45°
    when value +15 max Animation Is Idle
    when value -15 max Animation Is Idle
    when value -50 max Animation Is idle_LeftTurn45°
    hope you understand my problem and sorry form my english
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Mathf.DeltaAngle
     
    GarthSmith and cepoimario like this.
  3. cepoimario

    cepoimario

    Joined:
    May 2, 2014
    Posts:
    5
    thx a lot i've searched for this all night and found everything except this method :)
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Yeah. I wrote my own version of it once.

    Then I found it and slapped myself in the back of the head.
     
    cepoimario likes this.