# Problem with rotate

I tried to make a tree rotate like wind is blowing it and it’s working but first it makes a full loop over the x axis:

``````public bool hasReachedStartRotation = true;
public bool hasReachedFirstRotation = false;
public bool hasReachedSecondRotation = false;
public bool hasReachedLastRotation = false;

private float timeToReachRotation = 1;
private float baseTimeToReachRotation;

void Start()
{
baseTimeToReachRotation = timeToReachRotation;
StartRotating();

}

void StartRotating()
{
InvokeRepeating("RotateTheObject", 0.3f, 1 * Time.deltaTime);
}

void HasReachedStartRotation()
{
CancelInvoke("RotateTheObject");
}

void RotateTheObject()
{
if (hasReachedStartRotation)
{
if (timeToReachRotation > 0)
{
timeToReachRotation -= Time.deltaTime;
transform.Rotate(transform.rotation.x + .5f * Time.deltaTime, transform.rotation.y, transform.rotation.z - .5f * Time.deltaTime, Space.World);
}
else
{
timeToReachRotation = baseTimeToReachRotation;
hasReachedFirstRotation = true;
hasReachedStartRotation = false;
print(transform.rotation);
}
}
else
if (hasReachedFirstRotation)
{
if (timeToReachRotation > 0)
{
timeToReachRotation -= Time.deltaTime;
transform.Rotate(transform.rotation.x - .5f * Time.deltaTime, transform.rotation.y, transform.rotation.z - .5f * Time.deltaTime, Space.World);
}
else
{
timeToReachRotation = baseTimeToReachRotation;
hasReachedSecondRotation = true;
hasReachedFirstRotation = false;
print(transform.rotation);

}
}
else
if (hasReachedSecondRotation)
{
if (timeToReachRotation > 0)
{
timeToReachRotation -= Time.deltaTime;
transform.Rotate(transform.rotation.x - .5f * Time.deltaTime, transform.rotation.y, transform.rotation.z + .5f * Time.deltaTime, Space.World);
}
else
{
timeToReachRotation = baseTimeToReachRotation;
hasReachedLastRotation = true;
hasReachedSecondRotation = false;
print(transform.rotation);

}
}
else
if (hasReachedLastRotation)
{
if (timeToReachRotation > 0)
{
timeToReachRotation -= Time.deltaTime;
transform.Rotate(transform.rotation.x + .5f * Time.deltaTime, transform.rotation.y, transform.rotation.z + .5f * Time.deltaTime, Space.World);
}
else
{
timeToReachRotation = baseTimeToReachRotation;
hasReachedStartRotation = true;
hasReachedLastRotation = false;
print(transform.rotation);

}
}
}
``````

You are using the quaternion values in the Rotate function which takes Euler angles (angles in degrees). transform.rotation is a quaternion with xyzw values. XYZ is the rotation axis and w is the angle of the rotation and it’s normalized (1 unit in length), so it couldn’t be further from what you need. The Rotate function also just takes the degrees that you want to rotate, so you don’t pass it `transform.rotation.eulerAngles.x * 0.5f` Either as this will make the x axis rotation, which say already has a 45 angle, add an additional 22.5f to it.

So just give the Rotate function angles in degrees that you want to rotate around the x, y and z axis’.