Object appearing at destination not "Lerping"

Hi,

I do not understand why this script causes the object to jump to the destination rather than smoothly move to it?

	public GameObject Hand;
	public GameObject projectile;
	
	void OnCollisionStay2D (Collision2D coll)
	{
		if (Input.GetKeyDown (KeyCode.E)) {    
			if (coll.gameObject.tag == "Pickup") {
				if (Hand.transform.childCount < 1) {
					coll.gameObject.transform.position = Hand.transform.position;
					coll.gameObject.transform.parent = Hand.transform;
					projectile = coll.gameObject;
					//coll.gameObject.name = "Projectile";
				}
			}
		}
	}
	
	void Update () 
	{
			if (Input.GetMouseButtonDown (1)) {
					if (Hand.transform.childCount == 1) {
						projectile.transform.rotation = Hand.transform.rotation;
						projectile.gameObject.transform.parent = null;
						float shotDistance = 3;
						float time = 3;							
						projectile.transform.Translate(Vector3.Lerp (Hand.transform.position,Vector3.up * shotDistance,time));		
			}
		}
	}

Any help greatly appreciated,

Thanks,

This is because you are misunderstanding how to use the Lerp function.

Here’s a link to “how it works”. and here’s a link to another answer using it.

Now, to actually implement it in your code :

float delay = 0;
float timer = 0;
vector3 shotDistance; //I think you should be better using a vector here.

void Update () 
    {
            if (Input.GetMouseButtonDown (1)) {
                    if (Hand.transform.childCount == 1) {
                        projectile.transform.rotation = Hand.transform.rotation;
                        projectile.gameObject.transform.parent = null;
                        shotDistance = Vector3.up * 3;
                        timer = 3;
                        delay = timer;
            }
        }
        
        if (timer > 0)
        {
            timer -= Time.deltaTime;
            float dTime = delay - timer;
         projectile.transform.position = Vector3.Lerp (Hand.transform.position, shotDistance, dTime);

    }

}

Heck, I kinda got lost in keeping track of those floats, But i hope this actually leads you to a solution.

I can write a cleaner one if you really need one tho.

The last argument of the Lerp function should be a number between 0 and 1. If I read your code correctly, you set it to time=3, which gets clamped to 1, and so the Lerp function returns your destination position. Setting time to 0.3 instead of 3 would result in Lerp returning a position a third of the way to your destination.