我有两点,B
和A
。我在点A
处有一个对象,我希望遵循从A
到B
和h
中间点的抛物线轨迹,高度为{{{ 1}}。
我拍了一张照片,我希望它足够清楚:
这是我尝试过的(它是一个协程):
GameObject movingObject = this.movingObject; //this is the object I want to move
Vector3 pointB = target.position
Vector3 pointA = start.position
Vector3 direction = (pointB-pointA).normalized;
Vector3 nextTranslation;
float t, distance, distanceCovered, parameter, speed, startTime;
distance = (targetPosition-startPosition).magnitude; //distance between A and B
distanceCovered = 0;
p = 1000f; //parameter p for the parabola
speed = 10;
startTime = Time.time;
//travel only half the distance
while (distanceCovered < (distance/2)) {
t = Time.time - startTime; //elapsed time
//I use the parabole parametric equation to determine the next move
nextTranslation = new Vector3 (direction.x * parameter * t, (parameter/2) * Mathf.Pow(t, 2f), direction.z * parameter * t);
nextTranslation.Normalize ();
distanceCovered += speed;
pawn.transform.Translate(nextTranslation*speed, Space.World);
yield return null;
}
它有效,但参数p
似乎不会影响轨迹。我无法影响对象将停止的高度h
,无论我使用的参数p
如何,它总是相同的。