# Transform Rotate a certain angle (and back)

Hi everyone,

I am trying to rotate a game object with a certain degree (say -10) when a condition is met then rotate it back when that condition is off. I tried this:

transform.Rotate(-10*Time.deltaTime, 0, 0);

But this will keep rotating the object over time; Maybe I should add an angle variable but I don't know how.

I'll keep looking though:)

you are right about the variable

the piece of code above will rotate on the x axis by 10 degrees per seccond

you could use

fromRotation = transform.rotation; toRotation = Quaternion.Euler(x,y,z);
transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);

I am only a beginner in scripting so a lot to learn how to put things together. Naturally I missed a few things (not sure how to define the other variables in your example); This might be similar to another problem I have, maybe I will understand how transforming objects over time with variables like above (using time) or like in the next example: i am trying to rotate an object full 360 degrees without having to keep the button pressed; now I use:

var tumble = 360;

.... and in update function

if(Input.GetButton("Tumble"))

{
transform.Rotate(0, 0, tumble*Time.deltaTime);
}

Funny thing is I have both answers only they work each for the other question :) the behavior of the second example should be in the first one and the other way around. Bare with me here and try not to laugh too hard :)