I am trying to make an AirCraft that moves, and when you turn left or right, it leans in that direction smoothly, and when you release the turn key, it returns to its original rotation (smoothly again, but a bit faster).

So far I have this, and it only rotates the plane a little, and doesn’t return to its original rotation. Whats wrong?

``````        if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Translate (-1f, 0f, 0f);
if (leftLeaning > 0.0f) {
transform.Rotate(0f, 0f, 1.5f);
leftLeaning--;
}
}
if (!Input.GetKey(KeyCode.LeftArrow)) {
if (leftLeaning <= 1.0f) {
transform.Rotate(0f, 0f, 0.2f);
leftLeaning++;
}
}
``````

Also I don’t know how much in float numbers is 90 degrees and 0 degrees.

do this instead cause you cant use rotate to return to a rotation , rather use quaternion.slerp

if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Translate (-1f, 0f, 0f);
if (leftLeaning > 0.0f) {
transform.Rotate(0f, 0f, 1.5f);
leftLeaning–;
}
}
if (!Input.GetKey(KeyCode.LeftArrow)) {
if (leftLeaning <= 1.0f) {
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0f, 0f, 0f),Time.deltaTime);
leftLeaning++;
}
}

you might need to use localrotation instead of rotation in the slerp function but some testing will determine if its needed