Unity 5 getting bad values when using Mathf.Sin() and Mathf.Cos()

Good day comunity!

I am not sure If I am doing something wrong, but as far as I know the Sin and Cos values of the next angles are:

Sin(0) = 0
Sin(90) = 1
Sin(180) = 0
Sin(270) = -1
Sin(360) = 0

Cos(0) = 1
Cos(90) = 0
Cos(180) = -1
Cos(270) = 0
Cos(360) = 1

When using Mathf.Sin() and Mathf.Cos() in Unity II am not getting the correct values, I get these:

Mathf.Sin(0) = 0
Mathf.Sin(90)= 0.8939967
Mathf.Sin(180) = -0.8011526
Mathf.Sin(270) = -0.1760459
Mathf.Sin(360) = 0.9589157

Mathf.Cos()(0) = 1
Mathf.Cos()(90) = -0.4480736
Mathf.Cos()(180) = -0.5984601
Mathf.Cos()(270) = 0.984382
Mathf.Cos()(360) = -0.2836911

Edit:

Using this formula I got what I needed:

Debug.Log("0 " + (Mathf.Sin(Mathf.PI * 0 / 180)));
            Debug.Log("0 " + (Mathf.Cos(Mathf.PI * 0 / 180)));
            Debug.Log("90 " + (Mathf.Sin(Mathf.PI * 90 / 180)));
            Debug.Log("90 " + (Mathf.Cos(Mathf.PI * 90 / 180)));
            Debug.Log("180 " + (Mathf.Sin(Mathf.PI * 180 / 180)));
            Debug.Log("180 " + (Mathf.Cos(Mathf.PI * 180 / 180)));
            Debug.Log("270 " + (Mathf.Sin(Mathf.PI * 270 / 180)));
            Debug.Log("270 " + (Mathf.Cos(Mathf.PI * 270 / 180)));
            Debug.Log("360 " + (Mathf.Sin(Mathf.PI * 360 / 180)));
            Debug.Log("360 " + (Mathf.Cos(Mathf.PI * 360 / 180)));
2 Likes

Yeah, the Sin/Cos takes radians and not degrees so you need to multiply your value by Mathf.Deg2Rad

9 Likes

thanks man

2 Likes

please don’t do pointless necroposting. It’s against the forum rules
You can simply click the Like button instead.