Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

iTween animation framework for Unity ready for use!

Discussion in 'Scripting' started by pixelplacement1, Mar 24, 2010.

  1. dug1138

    dug1138

    Joined:
    Aug 10, 2010
    Posts:
    11
    CameraFadeTo stopped working when I moved from Unity 2 to Unity 3. At that time I had a slightly earlier version of iTween. I suspected that there may have been a fix/patch and downloaded and installed 2.0.33. After trying both versions of the syntax, the Hashtable and the Float form, I still can't get it to work again. Another programmer in my office working on a different Unity model has now discovered that they are having the same issue. We aren't getting any error messages. Thank you for your help.
     
  2. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Hello,

    I have a quick question and that is:

    When using iTween to do rotations or any movement like:

    iTween.RotateBy(gameObject,{"z":1, "LoopType":"PingPong"});
    iTween.MoveTo(gameObject,{"x":2,"time":2,"transition":"easeInOutBack"});

    Does it move in Time.deltatime or is it CPU?

    Im asking so I know that the speeds or movement will be the same across different types of computers and I am not sure? or Do I have to add in the Time.deltatime?

    Zeek
     
    Last edited: Oct 26, 2010
  3. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Are you first adding a camera fade with CameraFadeAdd()? Are you passing that a valid Texture2D? What exactly isn't working?
     
  4. dug1138

    dug1138

    Joined:
    Aug 10, 2010
    Posts:
    11
    Yay!

    Adding the camera fade, explicitly, with CameraFadeAdd() fixed the problem and everything is working again.

    Thank you. iTween rocks!
     
  5. TheLorax

    TheLorax

    Joined:
    Mar 25, 2007
    Posts:
    86
    Ok, I'm new to iTween (great by the way - thanks for it), and I've tried every combo I can think of to get this to work, but no go. What I'm trying is a simple experiment to get up and running.

    I have a path created out of transforms and I would like it so that every time I press a button, the test object moves a equal percentage(animates) along the path. I've had the gameObject move the entire path quickly and the gameObject move to a point on the path, but not use the path. Just need some guidance.

    Any help appreciated!

    Thanks

    TheLorax
     
    Last edited: Oct 26, 2010
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Does this work on Unity 3? I imagine it does. My finger itches to click that donate button already and I haven't even started! very nice work, thank you!
     
  7. schipman

    schipman

    Joined:
    Jan 22, 2010
    Posts:
    45
    This is one of the best things to have come for Unity. It has enhanced my personal projects soooo much!
    Keep up the good work!
     
  8. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Yes hippocoder it does work with Unity 3 :)

    Zeek
     
  9. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Thanks so much guys! I'm so glad it's helping you out!
     
  10. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674

    I'd suggest maybe using ValueTo() and PutOnPath()? That way you could ease to a percentage along the path. Hope that's at least something to get you rolling!
     
  11. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Hello TheLorax,

    What I did was this:


    var path : Transform[];

    function Update()
    {
    if(Input.GetButtonDown("Horizontal"))
    {
    tween();
    }
    }

    function OnDrawGizmos()
    {
    iTween.DrawPath(path);
    }

    function tween()
    {
    iTween.MoveTo(gameObject,{"path":path,"time":2,"orienttopath":true,"easetype":"easeInOutSine","oncomplete":"complete"});

    }

    Im thinking you need 3 points (transforms) to be able to see that the object is following the path. For example if I had PointA to PointB (which is just an empty game objects to use the transforms(drag and drop in the inspector)) The gameobject wouldnt do much but go back and forth.

    But when I add in a 3rd one PointA to PointB to PointC (move PointB in the game scene) You should now see the arc of all 3 points.

    Then Press Play and The Arrow Keys and My Cube follows the path but setup by Points.

    P.S. I didn't use the Prefab for the points (Gizmos) so they are not visible in this image but the curve or line is.

    Id like to know how you made it stop in between points though?

    I hope this is what you were asking for? Im a newbie to coding etc.. but hopefully moving fast :)

    Zeek
     

    Attached Files:

    Last edited: Oct 27, 2010
  12. dkoontz

    dkoontz

    Joined:
    Aug 7, 2009
    Posts:
    198
    Hello everyone, just thought I'd announced on here that I've released a visual editor for iTween. The announcement post on the forum is here and you can read the full writeup here. Feedback is appreciated.
     
  13. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Go grab it everyone, its awesome!
     
  14. TheLorax

    TheLorax

    Joined:
    Mar 25, 2007
    Posts:
    86
    Is there a relationship between the spacing of the transforms that make up a path and the way the percentage is read along that path between 0 and 1? I got my first test working with a simple cube moving incrementally around a circle path, but when I made a much more advanced path with tight curves, the cube moved what appeared to be smaller amounts around the curves. What I was doing is added the same amount to a value each time through, them using point on path and and the value coupled with moveTo to move increments around the board, but with the more advanced(tight) turns, the cube just doesn't move the same amount along the path. If I space the transform out evenly, I get better results, but a far less accurate curve. I'm probably doing something wrong, or maybe I'm without the right info.

    Thanks,

    TheLorax
     
  15. rafael.marteleto

    rafael.marteleto

    Joined:
    Aug 18, 2009
    Posts:
    1
    Hi Bob,

    I've made some ajustments to your EaseOutElastic (elastic) implementation based on Pedro's UnityTween, hope you find it useful:

    public static float elastic(float start, float end, float value)
    {
    end -= start;
    float d = 1f;
    if (value == 0) return start;
    if ((value /= d) == 1) return start + end;
    float p = d * .3f;
    float s = 0;
    float a = 0;
    if (a == 0f || a < Mathf.Abs(end))
    {
    a = end;
    s = p / 4;
    }
    else
    {
    s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
    }
    return (a * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) + end + start);
    }


    btw, thx for iTween, it rox!
    Rafael Marteleto
     
  16. dgutierrezpalma

    dgutierrezpalma

    Joined:
    Dec 22, 2009
    Posts:
    404
    I have been testing the Antares Project for creating a complex path that is travelled at a constant speed and it works greats... but I find easier creating the desired path with iTween because of the interpolation method used in Antares Project. At this moment I'm using Antares Project only for this functionality and iTween for everything else, but I'd rather use a single tool for everything, so my next question is if iTween could add (in a near future) a functionality like this:

    In Antares Project you define a list of points and it creates auto-magically a set of control points evenly spaced (you can control how many control points you want to be created) and as the control points are evenly space, the speed is constant during all the movement across the path. I know that it is easier said than done, but I think it would be a great addition to iTween.

    EDIT:
    I've just realized that I can use the iTween MoveTo method with the position of the first control point of an "Antares Curve". When the object arrives at the control point, I would call again the iTween MoveTo method with the position of the next control point... an so until the object arrives at the last control point. However, as I said previously, I'd rather create the path in iTween because of the interpolation method used.
     
    Last edited: Oct 29, 2010
  17. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674

    You rock back! Thanks, I'll get this in soon.
     
  18. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Cool. Sorry but I think that's over my current understanding of curves and available time threshold. Let's see if the community can cook it up and I'll put it in!
     
  19. dgutierrezpalma

    dgutierrezpalma

    Joined:
    Dec 22, 2009
    Posts:
    404
    Ok, I understand. I don't have any problem with using Antares Project for path movement and iTween for everything else. However, I have tried to use Antares Project and iTween together as I said in my last post and the results haven't been as good as I thought:

    Code (csharp):
    1.  
    2. public class CEnemy : MonoBehaviour{
    3.     public Curve path;          // Antares Curve
    4.     public Transform target;        // Where the it is looking at
    5.     public int currentCurvePoint = 0;   // Current Control Point
    6.     public float speed = 3;         // Speed in m/s
    7.  
    8.     public void StartMovement(){
    9.         Hashtable moveArgs = new Hashtable();
    10.         moveArgs["speed"] = this.speed;
    11.         moveArgs["easetype"] = "linear";
    12.         moveArgs["oncomplete"] = "OnControlPoint";
    13.         moveArgs["position"] =
    14.             this.path.curvePoints[this.currentCurvePoint];
    15.  
    16.         moveArgs["orientToPath"] = true;
    17.        
    18.         iTween.Stop(this.gameObject);
    19.         iTween.MoveTo(this.gameObject, moveArgs);  
    20.     }
    21.  
    22.     protected void OnControlPoint(){
    23.         this.currentCurvePoint++;
    24.         if (this.currentCurvePoint >= this.path.curvePoints.Length){
    25.             this.OnComplete(); 
    26.         }else{
    27.             this.StartMovement();
    28.         }
    29.     }
    30.  
    31.     // SOME PUBLIC METHODS
    32. }
    33.  
    Although the speed changes are not as noticeable as using iTween alone, they must been there because at the end of the path the objects aren't evenly distributed. I can also see a noticeable jitter at some points in the path (I suppose that this happens because when an enemy arrives at a control point it stop there until the next frame instead of continue moving for the rest of the frame). I don't know if this is the reason why objects doesn't move at a constant speed when I use iTween alone: if objects move at full speed on straights but they only move a little (and then wait until the next frame before continuing moving) on curves, that would explain the speed changes.

    If that is the problem, a posible solution could be to store in a variable how much movement has been spent before reaching a waypoint and then use the remaining movement to start moving towards the next waypoint immediately, without waiting for the next frame. You know the iTween code much better than me, could you check if my hypothesis is correct, please? If my hypothesis were right, could be applied the proposed solution without breaking something at another place in the code?
     
    Last edited: Oct 30, 2010
  20. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    I appreciate your efforts on this. I really don't have the time to dig into this right now (newborn, work is nuts, etc....) So let me know if you come up with something that I can add into iTween or if you find a solid workaround post your findings so others can learn from your work. Thanks!
     
  21. dgutierrezpalma

    dgutierrezpalma

    Joined:
    Dec 22, 2009
    Posts:
    404
    I also appreciate your efforts in developing iTween, it is fantastic and very easy to use. So don't worry about not having enough time for solving this issue, I understand perfectly that you can have more important things to do at this moment (congratulations for the newborn ^_^).

    As I said previously, I have found a valid solution for my current project using Antares Project for the path movement and iTween for everything else (it is less-than-ideal but at least it works). I really wanted to use iTween alone for this project, but I have spent too much time investigating this issue... I won't have enough time for further investigations until Christmas, so I wanted to share what I have found out, just in case somebody can find a solution for this... ;)
     
    Last edited: Nov 1, 2010
  22. Futurebear

    Futurebear

    Joined:
    Jan 11, 2010
    Posts:
    97
    is there any way to use a transform instead of a gameobject in an itween call? I want to :

    iTween.LookAt(transform, {stuff});
     
  23. dgutierrezpalma

    dgutierrezpalma

    Joined:
    Dec 22, 2009
    Posts:
    404
    If you have a transform, you can access to its gameObject:

    iTween.LookAt( transform.gameObject, {stuff} );
     
  24. Futurebear

    Futurebear

    Joined:
    Jan 11, 2010
    Posts:
    97
    Thank you david.
     
  25. groovfruit

    groovfruit

    Joined:
    Apr 26, 2010
    Posts:
    257
    I've been taking a look at the iTween demo, "PathExmple." There is a gameobject in the scene that moves between nodes. What I'm wondering is how I can instantiate prefabs of this gameobject at the point where the path begins? I tried just a very general Instantiate(GO) script, but when you make a prefab of the gameobject, it loses all of it's links to the path nodes on the stage.

    How can I get around this (short of hard-coding? node locations rather than have them as gameobjects on the stage... don't really want to do this).

    Cheers
     
  26. Futurebear

    Futurebear

    Joined:
    Jan 11, 2010
    Posts:
    97
    is there any way to use a transform instead of a gameobject in an itween call? I want to :

    iTween.LookAt(transform, {stuff});

    David's solution doens't work. Is there a way use a transform at a target instead of a gameobject?
     
  27. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Every transform has to be connected to a gameobject therefore grabbing the gameobect from it should work. Also there is no "LookAt" in iTween... it's "LookTo"

    Your solution is:
    iTween.LookTo(transform.gameObject, {stuff});
     
  28. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    You could make a prefab that has the path points in it and instantiate both and have something do a quick run through of all the points in the path prefab to generate the path to be moved along?
     
  29. Futurebear

    Futurebear

    Joined:
    Jan 11, 2010
    Posts:
    97
    thanks pixel, david was right, it was user error. Also I know about LookTo, just typo.
     
  30. groovfruit

    groovfruit

    Joined:
    Apr 26, 2010
    Posts:
    257
    Sounds like a good idea, but I'm concerned at the amount of memory this method might use, as I may have up to 20-30 instantiated objects in the scene at any one time... hmmmmmmmmm
     
  31. groovfruit

    groovfruit

    Joined:
    Apr 26, 2010
    Posts:
    257
    Hi

    I'm wondering, when using paths, is the point of the path where it starts at the node lined up to the centre of the gameObject or at another location on the object?

    I have a setup whereby the gameobject moves along a path from nodes A to B. When it hits node B, if a certain condition is met (detected by Collision), then it is to continue on path from nodes B to C.

    The only way I could get the collision detection to work at node B was to create 2 separate paths, as for whatever reason (unknown to a noob like I), if it were all one path from nodes A to B to C, and the object reached node B, the collision detection wouldn't work (would only work at the end of the path at node C).

    Anyways, my method so far works fine, however, when the object satisfies the condition and begins to enter the 2nd path at node B, there's a pause, and it does a bit of a 'twirl' if you like, before moving up the second path. I'd obviously like to get rid of this so that it appears to be a smooth transition moving from path 1 to path 2. Both paths share the same node that connects them (B). I've also set orienttopath to 0, and lookattime to 0, but that makes no difference.

    Any thoughts or ideas greatly appreciated. If you don't understand what I'm trying to do, I can mock up a quick pic ;)
    Cheers
     
    Last edited: Nov 13, 2010
  32. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    By default when you use MoveTo and the "path" parameter iTween will calculate a path for you to get the object to the first point of your path. I think this functionality is causing the "twirl" to that second path. Try adding "moveToPath" and setting it to false on that second path. Using a false "moveToPath" will snap your object to the first node on the path before it interpolated along.

    As for the collision issue, please note that iTween sets all objects it moves that have a RigidBody over to having isKinematic to true.
     
  33. groovfruit

    groovfruit

    Joined:
    Apr 26, 2010
    Posts:
    257
    Oh... because I set my object'sIs Kinematic to False in the inspector and whilst you say it gets switched to on, it does recognize the hit. (But doesn't if I set the Kinematic to true myself in the inspector)

    I'm not sure I understand the moveToPath, as it comes up as not being a member of iTween. Maybe I'm using it incorrectly.
     
  34. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    What version are you using?
     
  35. groovfruit

    groovfruit

    Joined:
    Apr 26, 2010
    Posts:
    257
    Version 2.0.13 is what I currently have installed.

    Ech, and please forgive me re "moveToPath" ...I've worked out what i was doing wrong (my spelling at 3am isn't always the best) *sigh*
     
    Last edited: Nov 14, 2010
  36. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Glad you figured it out. Just as a heads up iTween is up to version 2.0.36 now.
     
  37. Pelajesh

    Pelajesh

    Joined:
    Dec 7, 2009
    Posts:
    363
    I would like to know if there is an option for using iTween movements, but so that the object wont go through other objects if it has a collider. in other words can iTween understand collisions and deal with them as it should be done?
     
  38. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    iTween is built to be an animation tool. Therefore it will do exactly what you want at any cost in honor of the animation. My recommendation would be to simply call one of iTween's Stop methods when you detect a collision. Hope you can figure out a workaround.
     
  39. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    hi to all .

    why i can not use this :
    Code (csharp):
    1.  
    2. iTween.ColorUpdate(gameObject,{"color": Color.red,"time":1,"namedcolorvalue": "_TintColor"});
    3.  
    i using Particle/Alpha Blended

    and i have this error
    Code (csharp):
    1.  
    2. Material doesn't have a color property '_Color'
    3. UnityEngine.Material:get_color()
    4.  
    this code work gameObject.renderer.material.SetColor ("_TintColor", Color.red);

    Thank you
     
    Last edited: Nov 17, 2010
  40. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Not sure on that. Can you get me a simple example file I can look into?
     
  41. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    I've been using the iTween however I found something odd.

    I try to do the following:

    Code (csharp):
    1.  
    2. iTween.RotateBy (gameObject,Vector3(0,-360,0),2);
    3. iTween.MoveTo (Child,Vector3(0,1,0),2);
    4.  
    Both actions are execute on the gameObject or parent, the child is not affect by the script.
    Is there a way to do that?
     
    Last edited: Dec 4, 2010
  42. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    What are you putting in "Child"?
     
  43. linkthewise

    linkthewise

    Joined:
    Sep 26, 2009
    Posts:
    137
    Child is a camera find in the function awake with GameObjectFind();
    So its actually a gameObject. The cam is the child of an empty gameObject, that is the one that has the script. The empty gameObject is the one that do the first line.
     
    Last edited: Dec 5, 2010
  44. pickledzebra

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    Is it necessary to place gizmos at every vector point of the path?
     
  45. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Nope you can use anything you want or just use the visual editor.
     
  46. pickledzebra

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    Thanks for the pointer. I think I'm looking for something simpler. Can I just draw an arbitrary path by feeding DrawPath an arbitrary vector3? It seems the DrawPath has to be inside the OnDrawGizmos function?
     
  47. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    DrawPath() is strictly a visual representation and yes you need to call it from within your OnDrawGizmos() method.
     
  48. pickledzebra

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    I think I just need MoveTo(). I was making it too complicated. Thanks for the responses!
     
  49. tripod4unity

    tripod4unity

    Joined:
    Jan 4, 2011
    Posts:
    4
    Hi I recently purchased your Slider Menu demo, and the included project and scene works fine, but if I replicate the example in another project, the aspect ratio of the background image is incorrect. It's squished horizontally and a quarter of the second area is exposed from the very first position. It throws off the entire positioning. I'm using Unity 3 Pro and the latest iTween.
     
  50. tripod4unity

    tripod4unity

    Joined:
    Jan 4, 2011
    Posts:
    4
    I'm seeing strange behavior in general with Unity 3 with incorrect dimensions of images. Unity thinks the SliderVisuals.jpg is 1024x256. Any ideas why I'm getting the wrong size?