I created this version which uses a target position and t (time 0-1).
I would loop this function in an update function if (t < 1) t would increase by projectileSpeed * deltaTime in the update after the function was called
**AS THE PROJECTILE**
const float projectileHeight = 10f;
const float projectileSpeed = 5f;
Vector3 startPos;
Vector3 endPos;
float fireLerp = 1;
void FireProjectile(Vector3 firePoint, Vector3 targetPos)
{
startPos = firePoint;
endPos = targetPos;
// Setting the fire lerp to 0 will begin the fire animation
fireLerp = 0;
}
void Update()
{
if (fireLerp < 1)
{
Vector3 newProjectilePos = CalculateTrajectory(startPos, endPos, fireLerp);
transform.position = newProjectilePos;
fireLerp += projectileSpeed * Time.deltaTime;
}
}
Vector3 CalculateTrajectory(Vector3 firePos, Vector3 targetPos, float t)
{
Vector3 linearProgress = Vector3.Lerp(firePos, targetPos, t);
float perspectiveOffset = Mathf.Sin(t * Mathf.PI) * projectileHeight;
Vector3 trajectoryPos = linearProgress + (Vector3.up * perspectiveOffset);
return trajectoryPos;
}
[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]: https://i.sstatic.net/Eu8uX.png
[2]: https://i.sstatic.net/y6Cx4.png