rotate with sin and cos

how can I use the sin and cos for a rotation in a certain range? My object (based on position) must rotate between 0 ° and 90 °

if (GameManager.instance.currentDirection.dir == Vector2.right)
        {
            min = 0f;
            max = 90f;
             
        }
        else if (GameManager.instance.currentDirection.dir == Vector2.left)
        {
          
            max = 0f;
            min = -90f;
         
        }

         angle = Mathf.Clamp(angle, min, max);
         Quaternion rot = Quaternion.Euler(new Vector3(0,180,Mathf.Sin(Time.time)));

Why do you want to rotate with sin, and cos instead of just using the angle?

i need a reference between 0 ° and 90 ° or -90 ° and 0 ° as ping pong

I don’t get the code you posted. The last line is making use of sin but it doesn’t use anything from the code above.

But just for the rectords: sin and cos are working with radians rather than with degrees. so, the usual range is between -180° and 180° which is in radians between -Mathf.PI and Mathf.PI.

If you want to convert between degree and radians, you can do:

float degrees = UnityEngine.Random.Range(-180, 180);

float radians = Mathf.Deg2Rad * degrees;
float convertBack = Mathf.Rad2Deg * radians;

// The following assertion should not trigger because they are the same
// (or close to the same because of rounding errors)
Debug.Assert(Mathf.Approximately(degrees, convertBack));
1 Like

my character must rotate from 0 ° to 90 ° and then go back. For that I thought to use the sin. But how do I use the sin to specify the range?

sin is not for rotation. it is for getting the Y coordinate on a circle with a radius of 1 at a given angle (cos gets the X coordinate).

if(transform.localEulerAngles.x != lastXDegree)
{
lastXDegree = transform.localEulerAngles.x;

Debug.Log("transform.localEulerAngles.x = " + transform.localEulerAngles.x);

float xDegree = ((lastXDegree + 540) % 360) - 180;

Debug.Log("Convert X Degree = " + xDegree);

Debug.Log("Sin X = " + Mathf.Sin(xDegree));
Debug.Log("Cos X = " + Mathf.Cos(xDegree));
}

and you can convert the degree to sin cos :3