# Rotating without gimbal lock

Hey folks,

So I’ve taken a look around at a lot of the unity answers regarding this issue, but I can’t seem to get my head round it.

I’ve got a directional light in the center of my scene (my sun) and I’m attempting to have it Rotate 360 degrees on the x axis, while also rising and falling in the sky on the y axis. However, part the way through the rotation I’m losing control of the rotate. Perhaps someone could enlighten me?

This is the 24 hour rotation I am attempting to mimic: http://www.gdargaud.net/Antarctica/DC2005/Pano/SunRun_.jpg

``````	if (SunUp == true)
{
sun.transform.RotateAround(sun.position, Vector3.right, 10 * Time.deltaTime);
sun.transform.RotateAround(sun.position, Vector3.up, 10 * Time.deltaTime);
}

if (SunUp == false)
{
sun.transform.RotateAround(sun.position, Vector3.left, 10 * Time.deltaTime);
sun.transform.RotateAround(sun.position, Vector3.up, 10 * Time.deltaTime);
}
``````

Managed to solve it in the end! For those interested below is the answer:

``````public Transform sun;

public float yrot = 0;
public float xrot = 0;

private bool SunUp;

// Use this for initialization
void Start () {

SunUp = true;

}

// Update is called once per frame
void Update () {

if (sun.transform.rotation.eulerAngles.x >= 30)
{
SunUp = false;
}

if (sun.transform.rotation.eulerAngles.x <= 10)
{
SunUp = true;
}

if (SunUp == true)
{
xrot = xrot + 10 * Time.deltaTime;
}

if (SunUp == false)
{
xrot = xrot - 10 * Time.deltaTime;
}

yrot = yrot + 10 * Time.deltaTime;

sun.transform.eulerAngles = new Vector3(xrot, yrot, 0);

Debug.Log ("Sun Up: " + SunUp);
Debug.Log ("ypos: " + yrot + "xrot: " + xrot);

}
``````