Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Sin in degrees

Discussion in '2D' started by PhaseOne, Aug 1, 2020.

  1. PhaseOne

    PhaseOne

    Joined:
    Jul 27, 2020
    Posts:
    4
    Unity does Sin Cos etc in radians, how can I get a degree result for something like
    Code (CSharp):
    1. Mathf.sin(direction)
    Thanks
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,041
  3. PhaseOne

    PhaseOne

    Joined:
    Jul 27, 2020
    Posts:
    4
    So I've been trying that. this is what I had to get the degree answer for sin 180 (which should be 0)

    Code (CSharp):
    1. movement = Mathf.Sin(180 * Mathf.Rad2Deg);
    2. //and I also tried this
    3. movement = Mathf.Sin(180) * Mathf.Rad2Deg;
    I don't really know what to do... guess I'll keep working on it
     
  4. PhaseOne

    PhaseOne

    Joined:
    Jul 27, 2020
    Posts:
    4
    Ok figured this out! thanks for the reply, apparently I'm stupid or something idk :p
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,041
    @PhaseOne

    Well if you figured it out, why not share the solution here...
     
  6. PhaseOne

    PhaseOne

    Joined:
    Jul 27, 2020
    Posts:
    4
    oh ok
    Code (CSharp):
    1. movement = Mathf.Sin(direction * Mathf.Deg2Rad);
    I realized that my direction was in degrees (along with the rigidbody 2d "rotation") so I needed to convert the degrees into radians, where before I was trying to convert my 180 "radians" into degrees, which they already were.

    if that makes any sense
     
unityunity