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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Calculating angles using Atan2

Discussion in 'Physics' started by Clydey2Times, May 28, 2019.

  1. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    232
    Hopefully I'm asking this in the correct place. I'm following a Unity tutorial and I'm having trouble reconciling two methods of calculating angles.

    In one tutorial, the tutor uses the following line:

    Code (CSharp):
    1. float angle = 90- Mathf.Atan2(dirLookTarget.z, dirLookTarget.x) * Mathf.Rad2Deg;
    He didn't explain why he substracted the calculation from 90, so I sought out a more in depth tutorial on angles specifically. In this tutorial, the tutor uses the line:

    Code (CSharp):
    1. float angle = Mathf.Atan2(dirLookTarget.z, dirLookTarget.x) * Mathf.Rad2Deg -90;
    Why in one case does the tutor subtract the calculated angle from 90 and in the other case subtract 90 from the calculated angle? If someone could help me reconcile both approaches I would be extremely grateful.
     
    Last edited: May 28, 2019
  2. BoogieD

    BoogieD

    Joined:
    Jun 8, 2016
    Posts:
    236
    Sorry I'm no expert on trigonometry but the circle is divided into 4 quadrants each being 90 degrees. That probably has something to do with it. It's difficult to appreciate what the context of each equation is above.
    Have a a look at the below page with the interactive diagrams. Good luck!
    https://www.mathsisfun.com/algebra/trigonometry.html
     
  3. jankovalsky

    jankovalsky

    Joined:
    May 31, 2017
    Posts:
    14