Rotating the weapon back using Quaternion.Lerp

Hello everyone. I want to rotate my gun to left & right when player moves to left & right. So I made a code like this :

 var from : Transform; // a gameObject for start
    var to1 : Transform; // a gameObject which is for left limit of rotating ( 0,0,1.5)
    var to2 : Transform; // a gameObject which is for right limit of rotating ( 0,0,-1.5)
    var orig : Transform; // a gameObject which has the original rotations of gun(0,0,0)
    var current : Transform: // a gameObject for the weapons current rotation
    var speed = 0.1;
    private var rotateLevel : int =0; // a value to stop rotating left
    private var rotateLevel2 : int =0; // a value to stop rotating right

function Update(){
     transform.rotation =
          Quaternion.Lerp (from.rotation, to1.rotation, Time.deltaTime * speed);
    else if(Input.GetKey("d")){
     transform.rotation =
          Quaternion.Lerp (from.rotation, to2.rotation, Time.deltaTime * speed);


This works well, it moves smoothly & good according to the variables that I adjusted. But when I stop walking, it stays in the position which it was at. So all the aiming and other things get messed up. I need to turn the gun back to it’s original rotation smoothly. For that, I made a code like that but didn’t work :


 transform.rotation =
      Quaternion.Lerp (current.rotation , orig.rotation, Time.deltaTime *speed);

but as I said it did not work. I need help, any ideas ? Thanks =)


transform.rotation = Quaternion.Lerp( transform.rotation , from.rotation, Time.deltaTime *speed);

I’m not sure of what is the diff between from and orig though.