[英]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. 如果查看Vector3.Lerp的签名,您会注意到您为浮点数传递了3值。
The float should be from 0 - 1, 0.5 being midway. 浮点数应在0-1,0.5中间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.