# Rotation: rotate by a defined angle

Hi everyone,

I have been trying to get a smooth and visually pleasing way of have an object (plane in my case) tilt by about 50 degrees on a command.

So far I have tried:

Case 1:eulerAngle rotations --> Works pretty well but way to jerky (happening in one frame) if i added the Time.deltaTime it only did what the amount of degrees for 1 second.

Case 2:Quaternions --> Never got this to work well... continued to rotate when ever the button was pressed (could not get it to stop at 50 degrees).

Case 3: calling another function --> this by far works the best, however, if the key is lifted "GetButtonUp" before the angle movement for "GetButtonDown" is finished (ie: it only had time to go 20 degrees) the plane overshoots its level position.

In theory I feel like this should be really simple! heres a picture to make it clear (i eventually want to connect it to my GUI joystick, but for now I'm happy to get it working on a button down for keyboard)

for anyone looking for a similar solution:

--Heres the NEW code-- that I am using based on the answer suggestion for my situation

(there are still some issues with how I return to the flat, I will post the updated script when I work it out. Thanks for the help!**

``````var currentx = transform.eulerAngles.x;
var currenty = transform.eulerAngles.y;

if(Input.GetAxis("a")){

fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,110); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
}else{isTurning = 1;}

if(Input.GetAxis("d")){

fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,-110); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
}else{isTurning = 1;}

//isTurning   0=yes   1=no (so flatten out)
if(isTurning == 1){
fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
isTurning = 0;
}

``````