Hello everyone, I simply want to make my gun rotate a bit left while walking to the left. So I thought I can use Quaternion.Slerp, I used Unity’s example code :
var from : Transform;
var to : Transform;
var speed = 0.1;
function LateUpdate ()
{
from = myGun.transform;
if(Input.GetKey("a")){
myGun.transform.rotation =
Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed);
}
}
I made an empty gameObject, and rotate it a bit left, and I attached it as “to”. Now, when I press “a” key, it works weapon rotates to left as soon as it reaches to “to” gameObject’s rotation, but when I released “a” key, it suddenly rotates to it’s original rotation, I want it to rotate to it’s original rotation slowly and smoothly. In summary, what I want is, my gun will rotate left slowly when I press “a” , but then when I stopped pressing “a” key, gun will rotate to it’s original rotation slowly, how can I do that ? Thanks