I'd like to be able to direct a game object to move to a new target position over a certain amount of time. There are lots of different easing functions available, but for now let's say I'm just planning to use a standard quadratic ease-in ease-out function and also a quadratic ease-out function.
For example
Math.easeInOutQuad = function (t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t + b;
t--;
return -c/2 * (t*(t-2) - 1) + b;
};
Now suppose while it is still in the process of moving to that target and I want to give it a new target. Rather than have it instantly change directions with a zero starting velocity, I'd like a smooth transition.
How is this done mathematically and programmatically?
I want to avoid keeping a dynamic array of tween commands for every parameter of each game object. (I want to tween all sorts of parameters besides position.) that could get really heavy and bloated. But that's the only thing that comes to mind that might work... Keeping an array of active tweens and averaging all of them.
Maybe some easing functions lend themselves better toward being interrupted? Or is there a way to recalculate the four inputs to the ease function when a new target is set, such that the same function can continue to be used once per frame without a jarring speed/direction change, and ending at the second target instead?