4
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – rutter
    May 22, 2015 at 18:59
  • \$\begingroup\$ 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. \$\endgroup\$ Oct 14, 2016 at 7:59

2 Answers 2

1
\$\begingroup\$

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"
             ,"delay",.4,"easeType","easeInOutQuad"));
     }

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

     }
 }

Hope this helps!

\$\endgroup\$
1
  • \$\begingroup\$ 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? \$\endgroup\$
    – eternal
    May 22, 2015 at 19:00
1
\$\begingroup\$

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);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .