在Unity3d中,如何计算出特定时间行进距离所需的速度,炮弹与Sin()

In Unity3d, how to work out speed required to travel distance at specific time, cannonball with Sin()

我在没有刚体、没有 addforce 的情况下以炮弹模式移动对象。我需要计算出炮弹应该以多快的速度在正确的时间到达目的地。

到目前为止我的代码:

moveTimer += Time.deltaTime * ballSpeed;
Vector3 currentPos = Vector3.Lerp(startPos, endPos, moveTimer);
currentPos.y += height * Mathf.Sin(Mathf.Clamp01(moveTimer) * Mathf.PI);
this.transform.position = currentPos;

我知道通过增加 'ballSpeed',炮弹将遵循相同的曲线但速度更快。假设我想在 10 秒内精确到达 endPos,我该如何计算所需的 ballSpeed?

提前致谢!

ballSpeed = 1f / 10f; // duration 10s
...
moveTimer += Time.deltaTime * ballSpeed;
Vector3 currentPos = Vector3.Lerp(startPos, endPos, moveTimer);
currentPos.y += height * Mathf.Sin(Mathf.Clamp01(moveTimer) * Mathf.PI);
this.transform.position = currentPos;