I want to lerp a gun from positionA to positionB in relation to the main camera

I’m making an aiming down the sight script and i’v made my gun a child of the main camera,i want to lerp it in relation to the main camera when the right mouse button is being held, and when its not,lerp it back to positionA.Heres what i’v got so far, BTW it’s in c#:

using UnityEngine;

using System.Collections;

public class TheProperAimDownSight : MonoBehaviour{

bool lerp;

void Update (){

    lerp = true;
    lerp = false;

    transform.position = Vector3.Lerp(positionA, positionB, Time.deltaTime);
    transform.position = Vector3.Lerp(positionB, positionA, Time.deltaTime);


Instead of telling him/her how many times they have posted, why not just give a simple answer?

Your code is right, you just need to replace:

transform.position = Vector3.Lerp(positionA, positionB, Time.deltaTime);


transform.localPosition = Vector3.Lerp(transform.localPosition, positionB, Time.deltaTime);

For both of the lerps. Using localPosition will have it move relative to it’s parent (the camera) regardless of the parent rotating and moving, and if you want it to be able to smoothly go from any position inbetween to the target, it needs to lerp from it’s current position. So if you let go before it is fully aimed, it won’t snap to the aimed position and start moving back, it will be more like CoD per se.