Search Unity

Unity Mathf.Cos() is incorrect!?

Discussion in 'Editor & General Support' started by captainspaceman, Feb 7, 2021.

  1. captainspaceman

    captainspaceman

    Joined:
    Jul 14, 2017
    Posts:
    42
    cos(45) is 0.70710678118654752440084436210485, but Unity seems to think it is .525322

    I just spent like an hour trying to figure out why my code wasn't working and this turned out to be the problem.

    Just put "Debug.Log(Mathf.Cos(45));" in a start and throw the script on an empty game object to recreate.
     
  2. captainspaceman

    captainspaceman

    Joined:
    Jul 14, 2017
    Posts:
    42
    Ok it turns out Unity takes radian for the cosine argument. So instead of putting 45, for 45 degrees, put "Mathf.DegToRad * 45."