Can my lerp-function be optimized?

I have made this little tooltip-gameObject which is supposed to swap in and out new tooltips during the game.

I’m using a standard lerping functionality using a common “EaseOutBack”/“EaseInBack”.

Now I could not do a standard Vector3.Lerp over fromPosition and toPosition, since the EaseOutBack routine goes beyond the bounds of from and to. So I had to do this:

	IEnumerator SwapIn()
		Vector3 fromPosition = new Vector3(10f, 0, 0);
		Vector3 toPosition =;
		float lerpFactor = 0;
		float duration = 1f;
		float rate = 1.0f / duration;
		float tweenX = 0;
		float tweenY = 0;
		float tweenZ = 0;
		Vector3 localPosition =;
		while(lerpFactor <= 1.0f)
			lerpFactor += Time.deltaTime * rate;
			tweenX = EasingFunctions.EaseOutBack(fromPosition.x, toPosition.x, lerpFactor);
			tweenY = EasingFunctions.EaseOutBack(fromPosition.y, toPosition.y, lerpFactor);
			tweenZ = EasingFunctions.EaseOutBack(fromPosition.z, toPosition.z, lerpFactor);
			localPosition.Set(tweenX, tweenY, tweenZ);
			toolTipsContainer.transform.localPosition = localPosition;
			yield return null;
		toolTipsContainer.transform.localPosition = toPosition;

I really think this could be done prettier. In the future I would like to just use generic standard routines all over my game, so I could use an optimal representation of this snippet of logic.

Thank you in advance.

That isn’t doing any more work than a vector3 operation. In other words, the built-in Lerp also does math for x, then y then z. Regular CPUs don’t have any special fast way to do things to Vectors all at once (graphic cards do.)

If you just want to save keystrokes, make a function out of those middle four lines: Vector3 easeOutBack(V3 F, V3 T, float pct) { V3 res; res.x=EasingFunction.Ease...(F.x, T.x, pct) ...