Avert Fate camera/Gun movement

I have looked around on unity answers to find an answer to this quwstion but I can’t find a reliable answer. What I want to do is make it so that when I move the camera on my FPS controller the object I am holding will have a similar effect to the gun movements in Avert Fate. I would like some help with this.

I know what you’re talking about: is a kind of “smooth follow” effect, which adds some inertia to the weapon - when you change the camera direction, the weapon follows it with some delay (see this video).

The weapon is usually a camera’s child, thus it’s not so easy to create this effect - the child transform follows its parent automatically.

Since unparenting isn’t an alternative, the solution is to create an auxiliary variable curRot, which will follow the parent rotation with some delay, and assign it to the weapon’s rotation:

var speed: float = 15; // speed to follow camera
private var localRot: Quaternion;
private var curRot: Quaternion;

function Start(){
    localRot = transform.localRotation; // save initial local rotation
    curRot = transform.rotation;
}

function Update(){
    // targetRot follows instantly the camera:
    var targetRot = transform.parent.rotation * localRot;
    // curRot follows targetRot with some smoothing delay:
    curRot = Quaternion.Lerp(curRot, targetRot, speed * Time.deltaTime);
    transform.rotation = curRot; // update the actual weapon rotation
}

If you have several weapons childed to a common empty object (which is childed to the camera), add the script to this empty object. If not, add this script directly to each weapon. Ideally, the script should be attached to the object that effectively aims and shoots (or to its parent), thus the shots will follow the actual weapon direction.