简体   繁体   中英

Unity 2D c# Object appearing at destination not “Lerping”

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,

If you take a look at the signature of Vector3.Lerp , you will notice that you are passing a value of 3 for the float.

The float should be from 0 - 1, 0.5 being midway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM