0

I have a method, in which I am using the Cos() Function from the namespace "Mathf". Sadly, when I give, for example the in put of 45 it returns 0,52532, which is wrong. Using a calculator I get the correct answer of 6.283185 Radians.

float angle = 45; Debug.Log(Mathf.Cos(angle)); 

Prints out:

0,525322 

Can anyone help me out here? I am very confused right now

4
  • 2
    It doesn't take degrees, but radians Commented Sep 14, 2022 at 17:17
  • 1
    From docs: The input angle, in radians. Commented Sep 14, 2022 at 17:17
  • Cos gives a dimensionless value between -1 and +1, never 6 and never "radiants" Commented Sep 14, 2022 at 17:19
  • 1
    The first step when you get unexpected results is to check your expectations - which means to (re)read the documentation. Commented Sep 14, 2022 at 17:19

1 Answer 1

1

You need to convert to radians.

float angle = 45; Debug.Log(Mathf.Cos(angle * Math.PI / 180.0f)); 
Sign up to request clarification or add additional context in comments.

Comments