I’ve personally been using position interpolation alot and I made this code to fly in an arch when you throw the grenade and also rotate it randomly around itself.
Also uses an animation curve but for the flight path velocity and you can also use it to make something fly in a really funky way like to back and forth or speed up or anything.
{
[SerializeField] float rotationSpeed = 90;
Vector3 _targetPosition;
Vector3 _midPosition;
Vector3 _startPosition;
float timer;
float xRot;
float yRot;
float zRot;
public void Setup(GridPosition targetGridPosition, Action onGrenadeThrowComplete)
{
_targetPosition = LevelGrid.Instance.GetWorldPosition(targetGridPosition);
_startPosition = transform.position + Vector3.up * unitHeadHeight;;
_midPosition = Vector3.Lerp(_startPosition, _targetPosition, 0.5f);
_midPosition.y = arcHighPoint;
timer = 0f;
OnGrenadeExplodeThrowComplete = onGrenadeThrowComplete;
xRot = Random.Range(0f,180f);
yRot = Random.Range(0f,180f);
zRot = Random.Range(0f,180f);
}
void Update()
{
if(timer < _flightTime)
{
timer += Time.deltaTime;
float percentDone = timer / _flightTime;
Vector3 ab = Vector3.Lerp(_startPosition, _midPosition, _smoothcurve.Evaluate(percentDone));
Vector3 bc = Vector3.Lerp(_midPosition, _targetPosition, _smoothcurve.Evaluate(percentDone));
Vector3 ac = Vector3.Lerp(ab, bc, _smoothcurve.Evaluate(percentDone));
transform.position = ac;
transform.rotation *= Quaternion.Euler(rotationSpeed * Time.deltaTime,
rotationSpeed * Time.deltaTime,
rotationSpeed * Time.deltaTime);
}
}