Unity 2D c#出现在目的地的对象不是“0”;勒平”;

本文关键字:对象 勒平 2D 目的地 Unity | 更新日期: 2023-09-27 18:20:51

我不明白为什么这个脚本会导致对象跳到目的地,而不是平滑地移动到它?

    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));      
        }
    }
}

非常感谢任何帮助,

谢谢,

Unity 2D c#出现在目的地的对象不是“0”;勒平”;

如果您查看Vector3.Lerp的签名,您会注意到您正在为浮点值传递值3。

浮动应该在0-1之间,0.5在中间。