# Universal Tween Engine - simulating time T instantaneously

I have a circuit in Universal Tween Engine in libgdx and I want to make several entities follow this path

, each behind the other, like body pieces of a snake. The problem is that I need to find the initial position for each piece. I could obtain this effect by setting every piece to one point and setting incremental delay times for each one, and when the largest delay ends, I have something like this, with the last entity at the origin point

The problem with this is that the full formed "snake" must be like this when the level starts, that means, time = 0. How can I achieve this instantaneously?

• can you show us the code you wrote? Nov 27 '13 at 8:07

Your problem is that you are using t and moving the time forward, in a parametric equation t represents any varying quantity and that doesn't strictly mean you should move the time forward. This can be simply achieved by writing an interpolation in a loop and increment t just at initialization time.

// call this at initialization time
int stepsCount = 10; // Change depending on the object count, assuming 10 objects here
float step = 1.0f/(float)stepsCount;
float t = 0.0f;
for (int i=0; i < stepsCount; i++, t+=step)
{
// depending on your interpolation equation, just pass t as a param
objectPos[i] = Interpolate( initPos, finatP, t);
}


This will set the position for each object depending on t, the first object when t=0 will be at initPos, and when t=1 the final object will be at the finalPos. In case you don't want the objects to span the whole interval, we need to scale the step accordingly.

// This is one way to do it
float step = 1.0f/(float)stepsCount;
step *= scaleFactor;


scaleFactor = 0.5 will take half the interval. In case you want to determine the scaleFactor base on some position, you need to calculate it by taking the inverse interpolation, in other words you need to get the parametric quantity that represents that position on the line/curve.