Vector3 SampleParabola(Vector3 start, Vector3 end, float height, float t)
{
if (Mathf.Abs(start.y - end.y) < 0.1f)
{
Vector3 travelDirection = end - start;
Vector3 result = start + t * travelDirection;
result.y += Mathf.Sin(t * Mathf.PI) * height;
return result;
}
else
{
Vector3 travelDirection = end - start;
Vector3 levelDirecteion = end - new Vector3(start.x, end.y, start.z);
Vector3 right = Vector3.Cross(travelDirection, levelDirecteion);
Vector3 up = Vector3.Cross(right, levelDirecteion);
if (end.y > start.y) up = -up;
Vector3 result = start + t * travelDirection;
result += (Mathf.Sin(t * Mathf.PI) * height) * up.normalized;
return result;
}
}
网友评论