Search Unity

iTween animation system

Discussion in 'Assets and Asset Store' started by pixelplacement1, Apr 13, 2010.

  1. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    iTween 2.0 feature tease:

    iTween 2.0 will have a new method to allow you to animate anything that iTween doesn't have a specific method for! All you need is to provide a "start" and an "end" float and a call-back method that accepts a float and applies the value to what you need it for.

    For example, say you needed to animate a camera's field of view - iTween doesn't have a specific method to handle this so you can now use the new iTween.value():

    Code (csharp):
    1. function Start () {
    2.     iTween.value(gameObject,{"start":100, "end":60, "onUpdate":"tweenValue"});
    3. }
    4.  
    5. function tweenValue(value : float) : void{
    6.     camera.fieldOfView=value;
    7. }
    What if you needed to animate a light's intensity? No problem!

    Code (csharp):
    1. function Start () {
    2.     iTween.value(gameObject,{"a":0, "b":4, "onUpdate":"changeLightIntensity"});
    3. }
    4.  
    5. function changeLightIntensity(value : float) : void{
    6.     light.intensity=value;
    7. }
    I promise I'll have 2.0 and it's support materials done as soon as I can.
     
  2. yosh

    yosh

    Joined:
    Mar 13, 2009
    Posts:
    142
    Hi,

    i simple want to tween an alpha-value, so i´m using the "fadeTo"-function, but it crashes my unity-application.

    Code (csharp):
    1. iTween.fadeTo(overlay, 1f, 0f, 5f);
    or

    Code (csharp):
    1. iTween.fadeTo(overlay, 1f, 0f, 0.5f);
    Any ideas, any workaround?
    Thanks for your help..
     
  3. pcorkum

    pcorkum

    Joined:
    Mar 28, 2010
    Posts:
    6
    Make sure that you are using the latest version (33) of the CS script. There was a defect that was causing infinite recursion.
     
  4. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Do you have any errors thrown when it dies? Also, is 'overlay' a GameObject? If you comment out the iTween involvement does the program still crash?
     
  5. Nerosis

    Nerosis

    Joined:
    Jan 4, 2010
    Posts:
    14
    Using hashtables in C# like they are used in JavaScript isn't going to be elegant or easy to read.

    If I may, I suggest using the same method that Unity uses for passing GUILayoutOptions into GUILayout functions. Calling iTween functions using this method would look like this:

    Code (csharp):
    1. iTween.rotateFrom(target, iTween.y(90f), iTween.time(1.5f));
    2. iTween.moveTo(target, iTween.y(1.2f), iTween.delay(4.6f));
    This is cleaner than using C# hashtables, and enforces the correct type for each argument, while still allowing the user to pass in only the arguments that they want to specify.

    I've attached an example of how to implement this.
     

    Attached Files:

  6. yosh

    yosh

    Joined:
    Mar 13, 2009
    Posts:
    142
    @pixelplacement1
    Thanks for your answer. No, i get nor error-ouput. Yes, "overlay" is ja gameobject. If i comment the iTween line out, it doesn´t crash...
     
  7. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    What version are you using?
     
  8. yosh

    yosh

    Joined:
    Mar 13, 2009
    Posts:
    142
    @pixelplacement1:
    I´m using the latest 1.0.32 for c#. What range of float values are accepted?

    Edit: Range is from 0f to 1f, right? (ex: Color.a(0f/255f) or Color.a(255f/255f)..
    Thanks for your help..
     
  9. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Are you looking for colorTo parameters? Does this help: http://www.insquare.com/iTweenDoc/html/M_iTween_colorTo_5.htm
     
  10. pcorkum

    pcorkum

    Joined:
    Mar 28, 2010
    Posts:
    6
    This is clever. I wish they supported C# 4 which gives named variables and optional variables. However, your idea is a clever hack. However, there are downsides that I am not fond of. For instance, you lose compile time checking to ensure that you have not duplicated parameters. Also, you lose performance in parsing the parameters, although I don't think it would break the bank.

    Having led development teams, there are certain "values", so to say, that I think are important to developing rigid applications quickly that are easily modifiable if necessary. One of those "values" is "errors at compile time are always significantly better than errors at run-time".

    I will give it some serious thought.
     
  11. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Just wanted to let everyone know that things certainly aren't "quiet" on the iTween development cycle. Myself and a few fantastic contributors are working like crazy to make 2.0 your "dream come true" for everything you truly want to do easily and amazingly in Unity.

    Bare with me on the bugs everyone has found and thanks for all of your support.
     
  12. Nerosis

    Nerosis

    Joined:
    Jan 4, 2010
    Posts:
    14
    Yeah, it's a downside. I spent quite a while looking for a way around this without specifying every possible parameter, but I'm not sure it's possible. Neither the C# or JS implementations that accept hashtables can check this at compile-time, though. This will not be an issue with C# 4.

    The parsing of parameters will only occur once, and then the animation will run for quite a few frames using the parameters as cached in the Arguments struct, so I don't think it will have much of an impact.

    Agreed.

    I hear you! Named and optional variables would allow C# to access iTween exactly the same way that JS can, but with compile-time parameter type and duplication checking, which if I dare say it, would mean that C# wins. :wink: However the functionality in C# 4 requires that Unity support Mono 2.8, which seems unlikely anytime soon.

    I experimented with all the possible ways I could think of for calling iTween functions with C#. I've posted a short snippet of the usage of each method below:

    Method 1 (as previously suggested)
    Code (csharp):
    1. iTween.moveTo(target, iTween.y(100f), iTween.time(4.6f));
    Method 1.5 (method 1 with helper MonoBehaviour)
    Code (csharp):
    1. iTween.moveTo(target, y(100f), time(4.6f));
    Method 2
    Code (csharp):
    1. iTween.y = 100f;
    2. iTween.time = 4.6f;
    3. iTween.moveTo(target);
    Method 3 (an inlined variation of method 2)
    Code (csharp):
    1. iTween.moveTo(target, delegate { iTween.y = 100f; iTween.time = 4.6f; } );
    Method 3.5 (method 3 with helper MonoBehaviour)
    Code (csharp):
    1. iTween.moveTo(target, delegate { y = 100f; time = 4.6f; });
    Method 4 (C# hashtable implementation that compiles in Unity 2.6)
    Code (csharp):
    1. Hashtable args = new Hashtable();
    2. args.Add("y", 100f);
    3. args.Add("time", 4.6f);
    4. iTween.moveTo(target, args);
    5.  
    6. //OR
    7.  
    8. Dictionary<string, object> args = new Dictionary<string, object>();
    9. args.Add("y", 100f);
    10. args.Add("time", 4.6f);
    11. iTween.moveTo(target, args);
    Method 5 (C# hashtable implementation that requires C# 3)
    Code (csharp):
    1. iTween.moveTo(target, new Hashtable() { { "y", 100f }, { "time", 4.6f } });
    2.  
    3. //OR
    4.  
    5. iTween.moveTo(target, new Dictionary<string, object>() { { "y", 100f }, { "time", 4.6f } });
    The "helper MonoBehaviour" refers to custom class that can be inherited from instead of MonoBehaviour when calling iTween from inside a script that must inherit from MonoBehaviour. A class like this could be optionally used to remove the need to prefix everything with iTween.

    I believe method 1/1.5 still offers the best overall option of those I've investigated.
    Method 2 is clean and safe, but doesn't follow the usual iTween way, so that's probably not a good idea.
    Method 3/3.5 is interesting, but maybe just a little too easy to abuse.
    Method 4 shows how hashtables would need to be used in the current version of Unity.
    Method 5 requires that the Mono version be upgraded to support C# 3 collection initializers, so it will have have to wait for Unity 3.

    Sorry for the long post - I hope it helps...
     
  13. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Truly appreciate your input on this!

    I do have a plan of attack on this for iTween 2.0 and an overall long-term direction for the actual tool itself. So, hang tight for the next release - and if anything else pops into your head please let me know!
     
  14. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    I've been trying out iTween (the c# version) and I do like it very much. One question though, is there going to be an iPhone friendly release of 2.0 or the current iteration?
    The C# version uses generics for the beziers and such, and Unity iPhone isn't all that happy about that. :)
     
  15. dkoontz

    dkoontz

    Joined:
    Aug 7, 2009
    Posts:
    198
    Are you on iPhone 1.7? Generics support was added in 1.6. Is it a specific method that's not genericized like GetComponent that's causing problems?
     
  16. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Also, is your .NET set to 2.1 under Player Settings?
     
  17. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    Yes, I am using iPhone 1.7, and .NET is set to 2.1 in player settings.
    The iTween script itself isn't compiling to begin with. It's not accepting the List<Vector3> Beziers line (not a valid identifier exception) in the arguments struct for some reason. Maybe I missed something here or I'm just being thick again :), but it seems to compile just fine in Unity Basic.

    edit: I will double check everything when I get off work though!
     
  18. happybomb

    happybomb

    Joined:
    Apr 22, 2010
    Posts:
    21
    Ive just been playing around with iTween. Well done Bob, good stuff!

    I have a bit of a problem: When I apply a scale tween to a gameobject it works, but any additional scale tweens to the same gameobject makes it reverts back to its original scale before applying the new tween.

    Cant seem to find the answer anywhere. Im doing something stupid right?
     
  19. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Nope, your frustration is my fault. The current version of iTween is a bit of a mess and you found a bug that I'm well aware of. 2.0 fixes this and if you absolutly can't proceed as a result of this let me know and I'll get you the beta of 2.0.

    Thanks for the support and sorry for this speed bump.
     
  20. yosh

    yosh

    Joined:
    Mar 13, 2009
    Posts:
    142
    Hi,
    at first.. thanks for your time developing iTween.
    It´s really great.

    But i´ve a question for the "oncomplete" value - my code below doesn´t jump in my function. Maybe you could have a look, please:


    Code (csharp):
    1. private void Invisible()
    2.     {
    3.         iTween.moveTo(textObj, 1.5f, null, endPos, iTween.EasingType.easeInExpo, "SetInactive", "false");
    4.     }
    5.     private void SetInactive(string param){
    6.         print("SetInactive: " + param);
    7.          textObj.SetActiveRecursively(false);
    8.          flagHotspotPressed = false;
    9.     }
    I get no output from the "SetInactive"-function.. Any ideas? Where´s my fault?
     
  21. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    This should help: http://forum.unity3d.com/viewtopic.php?t=53025&highlight=itween
     
  22. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    Never mind what I said earlier. I wasn't using the latest and greatest version (1.0.34, I was at 1.0.32). Sorry about that!

    It's working beautifully now. For a minute there, I thought I had to go back to Ani.Mate. :D
     
  23. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Any thoughts on the Bezier interpolations ?
     
  24. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Yup, looks like we are going with Hermite Cardinal Splines and I have 2 contributors helping with the new curveTo and curveFrom methods which will take an optional "classic":boolean property which will allow the previous moveToBezier equation. I'm also deprecating a few things (with friendly errors to help everyone with the changes).

    I'll let everyone know when things are ready.
     
  25. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Sounds pretty good. :)

    An other question, have you implemented any start-end interpolation parameter?
    For example, a float value betwen 0 and 1.
    - 0 means that the bezier function returns (or stop at) the starting position of the bezier path.
    - 1 means that the bezier function returns (or stop at) the ending position of the bezier path.
    - 0.5 its half path, and so on.

    And so, we can control the current position (on the bezier path), with a single float parameter.
    [EDIT]
    Is not that much an interpolation thing. What i mean is some kind of "SetPositionOnBezierPath()" based on a float parametter. This function should look like:
    Code (csharp):
    1. newPos = SetPositionOnBezierPath(node1, node2,..., nodeN, amount);
    This function should return (or compute) the current position based on the "amount" param.

    To get a better idea, imagine a timeline Editor,
    each keyframe is a node, then i give to the timeline a float value between 0 and 1, then it returns me the currentPlay position. Zero is the start of timeline animation and One is the end of that timeline animation.

    If you need any further explanation about how this function should behave, just reply or PM me. :)

    Tanks for your hard work guys, keep going!
    Cheers,
     
  26. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    I'll see what I can do as far as an interface for this functionality once the new curve() methods are established. ;)
     
  27. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Alright,
    Tanks for your support again,
    Cheers,
     
  28. cyangamer

    cyangamer

    Joined:
    Feb 17, 2010
    Posts:
    234
    This is a fantastic script and I appreciate all the work you've put into it! I have a question:

    I'm using this script with a Finite State Machine (for my enemy AI) and the FSM needs to use FixedUpdate as opposed to Start() or a Coroutine, so my functions repeat themselves every frame. The delay you've put in is pretty sweet, but the problem with Update() is that the commands after the animation will execute before the animation is even finished!

    Example (C#):
    Code (csharp):
    1. npcPos = npc.transform.position;
    2.         playerPos.x = player.transform.position.x;
    3.         playerPos.y = npc.transform.position.y;
    4.         playerPos.z = player.transform.position.z;
    5.         if (!attacked)
    6.         {
    7.             iTween.moveTo(npc, 0.2f, null, playerPos);
    8.             iTween.moveTo(npc, 0.1f, 0.2f, npcPos);
    9.             attacked = true;
    10.         }
    11.         attacked = false;
    12.         npc.GetComponent<EvilBoxCC>().SetTransition(Transition.Defend);
    attacked is a boolean to make sure the animation plays only once. However, as you can see, I have to immediately transition to the next state in my FSM, and this cuts off my model's animation.

    Granted, this doesn't solely involve your script, but it does involve it so if you had a suggestion of how to work around this, I'd appreciate it. :)
     
  29. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    This is truly amazing.

    I can't believe its free and so thoroughly documented.

    You just earned a six pack.

    Thank you.
     
  30. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Sorry I can't be much help on this one. I can offer than 2.0 plays nicer with usage in the Update function and, if you think it would be necessary, I can put a boolean in that would (since 2.0 runs everything in Update and not as coroutines to enable pausing of tweens!) allow you to force the iTween to run in FixedUpdate instead. Useful?

    Care to teach an old dog new tricks and maybe give me some help on learning FSMs? I'm a designer by history and a coder by brute force. Maybe send me an email to teach me some tricks?
     
  31. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    To know I'm helping out keeps me going on the DRAGGING I've begun to do on getting 2.0 done. Any WordPress theme gurus able to lend a hand with the new support site development?
     
  32. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
  33. lancerfour

    lancerfour

    Joined:
    Feb 24, 2010
    Posts:
    24
    awesome really, really looking forward to 2.0.
     
  34. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Me too! I dream about iTween and my wife is soooo tired of hearing about it ;)
     
  35. lancerfour

    lancerfour

    Joined:
    Feb 24, 2010
    Posts:
    24
    lol, i know the feeling :D
     
  36. interactiveboy

    interactiveboy

    Joined:
    Jul 31, 2009
    Posts:
    21
    Excellent!

    I anxiously await the update. Thank you for all your hard work. It is seriously a NEEDED framework.

    You are earning major karma points for this, ya know it?
     
  37. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    After some learning and help, I'm settling on Catmull–Rom splines for iTween 2.0 to replace the bezier control from version 1.0 to increase control and reliability of path setting.

    Any thoughts?
     
  38. Robert G

    Robert G

    Joined:
    Nov 17, 2009
    Posts:
    233
    Does that mean the "overshooting" will be gone or less?
    Probably hard to answer for you right now I guess.

    Good luck, Robert
     
  39. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    From what I'm reading I'm going to hypothesize on it removing the overshoot. I'll let you know for sure once I get a working solution and equation in place. This whole thing has been quite a learning experience.
     
  40. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    err, why does my iphone game framerate drop considerably when I use iTween, but doesnt when I use regular transform.Translate?
     
  41. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Can you give me a code sample?
     
  42. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Here:

    Code (csharp):
    1. if (controller.animType == 1){
    2.             iTween.moveBy(gameObject,{"z": .2, "time": .3});
    3.             animation.Play ("att1");
    4.                
    5.                        
    6.         }else if (controller.animType == 2){
    7.  
    8. iTween.moveBy(gameObject,{"z": .2, "time": .3});
    9.             animation.Play ("att2");
    10.                
    11.            
    12.         }else if (controller.animType == 3){
    13. iTween.moveBy(gameObject,{"z": .3, "time": .7});
    14.             animation.Play ("att3");
    15. }
     
  43. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Are you running this in an update function?
     
  44. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    yes it is in Update.

    BTW, iTween is an awesome idea.
     
  45. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674
    Thanks!

    iTween 1.0.xx doesn't really work well in Update functions. You should use moveToUpdate if you really need to use it this way. Or.... wait until 2.0 is done (I swear I'm in the home stretch now) as it has been rewritten from the ground up to work better in every situation including Update functions.

    As it currently stands, using iTween 1.0.xx in an Update function would be an extremely expensive solution on the iPhone.
     
  46. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    OK, Ill try that.
     
  47. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674


    iTween 2.0 Bad news and good news.

    Bad news: I removed iTween.moveToBezier() (and lots of other things but I'll provide info to help out with what's new and changed.)

    Good news: You can throw a "path" property into iTween.MoveTo() or iTween.MoveFrom() as either an array of Vector3s or Transforms and it will move your GameObject based on the much more solid Catmull-Rom spline.

    How's this for absolutely hot: Expose an inspector array for Transforms that you can drag in at your leisure (go ahead an make gizmos that you can use to plot a path for a camera path editor) and make an object follow the path in one line of code.

    Code (csharp):
    1. public Transform[] points;
    2.     void Start(){
    3.         iTween.MoveTo(gameObject,iTween.Hash("path",points,"time",4));
    4.     }
    Oh yeah, forgot to mention that with iTween 2.0's completely rebuilt core you could even run this setup in an Update loop and it would allow you to fly an object through dynamic points.

    Hot?

    P.S. You more observant guys may notice the universal approach to setting the HashTable that iTween needs to make the interface identical between JS, C# and BOO. Don't worry if you don't like it; you can bypass it and just create a Hashtable anyway you want but this approach greatly reduces the code necessary in C# to create a Hashtable (credits to David Koontz for this approach).

    P.P.S. Special thanks to andeeee for his Catmull-Rom class: http://forum.unity3d.com/viewtopic.php?p=218400#218400

    P.P.P.S Sincere apologies to David Koontz for his work on a new spline solution that I ended up not using. I truly hope there's no hard feelings. iTween is as much for me as it is for the community and I wanted to learn everything I'm putting into this big beautiful obsession of mine.
     
  48. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674


    iTween 2.0.00 is live!

    I'm sure there's still a few bugs and inconsistencies in the documentation and code (I really ran out of steam).

    Let me know what you think, what you hate and what needs fixing.

    http://itween.pixelplacement.com

    Thanks guys!
     
  49. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Cool! Ill give it a try now...
     
  50. pixelplacement1

    pixelplacement1

    Joined:
    Aug 19, 2009
    Posts:
    674