Is there any way to change the default mouse look script so that if its attached to my gun it moves my gun around but it smoothly glides back to its starting position instead of moving and staying in the new position, Im trying to make my gun have sort of a sway movement when you look around. (its very common in modern shooters), if anyone could help me I would be very great full.
First, you need to lerp between the current rotation and the default rotation. Use Time.deltaTime and a speed as t parameter.
Then, you need to decide when this is performed. I’d say when those two rotation are different which means the player moved the mouse, but with a timer reset every time the player actually move. It would look like that :
function Update()
{
if( Mouse move )
timer = WAIT_BEFORE_CENTER_WEAPON;
if( timer > 0 )
transform.rotation = Quaternion.Lerp( transform.rotation, defaultRotation, Time.deltaTime * speed );
timer -= Time.deltaTime;
}