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



我正在以炮弹模式移动一个物体,没有刚体,没有加力。 我需要计算出炮弹在正确的时间到达目的地的速度应该有多快。

到目前为止我的代码:

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 = 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;

最新更新