# Start iTween MoveTo from a specific node? (Unity)

I just started using iTween as part of my day/night cycle. I'm trying to move the sun and moon along a curve, but I want have the sun/moon start at a specific location depending on the time of day. That would mean beginning the MoveTo() function from, say, the 3rd node instead of the 1st node, but I can't figure out how to access specific nodes.

If that's not possible, is there some other workaround? I thought of making several paths of two nodes each and calling the next path once the first one finishes, but then the object has to move in a series of straight lines.

• You could create a second array of points and use your original data to populate that in your desired order. If all you need is a simple orbit, though, it might be easier to attach the sun/moon to a faraway pivot point (like a parent transform), then rotate around that. – rutter May 22 '15 at 18:59
• First of, don't try to animate it with a path, nodes. It is possible to achieve this way simpler. Just use a parent game object, set the sun offside from the pivot of parent gameobject and rotate the gameobject. That way the sun is rotating around a certain radius. Now you can calculate, how big the radius has to be to look like you want the behaviour to be. – Yosh Synergi Oct 14 '16 at 7:59

You must call iTween once. You would then call it each update. For example:

 public class doubleTween : MonoBehaviour {

// Use this for initialization
void Start () {
iTween.RotateBy(gameObject,iTween.Hash("x", .25,"time",2, "easeType"
, "easeInOutQuad", "loopType", "pingPong", "delay", .2));

iTween.MoveTo(gameObject,iTween.Hash("x",6,"time",4,"loopType","pingPong"
}

// Update is called once per frame
void Update () {

}
}


Hope this helps!

• Thanks, but I'm already only calling it once. The problem is: let's say the sun should start on the left side of the screen if it's 10:00am in game time, and it should start on the right side if it's 5:00pm. Both 10:00am and 5:00pm can be represented by a node, but how can I tell the sun to begin at 5:00pm rather than 10:00pm? – eternal May 22 '15 at 19:00

I am still not sure how to start at an exact percentage, but you can start from a specific node with something like this:

public int PathShift;

void Start() {

Vector3[] UsePath = iTweenPath.GetPath("MyPath");
ShiftArray(UsePath, PathShift);

iTween.MoveTo(
gameObject,
iTween.Hash(
"path", UsePath,
"time", 200,
"orientToPath", true,
"moveToPath", false,
"loopType", "loop",
"easetype", "linear"
)
);

}

public static void ShiftArray<T>(T[] arr, int shift) {
shift = shift % arr.Length;
T[] buffer = new T[shift];
System.Array.Copy(arr, buffer, shift);
System.Array.Copy(arr, shift, arr, 0, arr.Length - shift);
System.Array.Copy(buffer, 0, arr, arr.Length - shift, shift);
}