Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LeanTween - A tweening engine that is up to 5x faster than competing engines!

Discussion in 'Assets and Asset Store' started by dentedpixel, Dec 3, 2012.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @Dentedpixel - Looked at that script some time back and the behavior wasn't exactly what I was looking for. Thanks for the tips, I'll investigate those as well.
     
  2. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    Hey,

    Apologies if this has already been covered, but couldn't see it anywhere, but is there any way of using local space with LeanTween. I see there is a moveLocal option, however that doesn't support a 'path' array, as I am using the visual path tool as well. If not then that's going to be an issue for what I am trying to do.

    Nice lightweight tweening engine though!
     
  3. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey @OriginalBadBoy, that is a good point, nobody has requested that feature yet, but it seems like a good thing to add (and relatively easy to). I will try to get that in, in the next couple of days or so.

    I am glad you are liking LeanTween otherwise!

    P.S. So you are the person using the Visual Path tool! No seriously there has only been one download :p I hope it's serving your purposes ok, I am hoping to add other features to the LeanTween Editor later down the road...
     
  4. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    LOL ... Really I am the only person? Its handy if you trying to make a galaga style game with all those predefined patterns, and OK there are other ways of doing it, but visually its nice to actually see the pattern so you can tweak it to perfection. I was never very good at maths!

    In the end I can always use one of the other tween solutions for that part of the enemy movement, it just seemed like such a strange thing to not include I thought I was missing something obvious! For the main enemy entrance patterns (in a galaga style game) using a tween engine (for me anyway) seems to be the best solution.

    Entrance patterns and synchronizing all the enemies movements on the screen is done, it was just additional patterns (such as swooping down the screen) that obviously require the local space of the current enemy to start its pattern from was were I got stuck. As stated for now I can just use iTween for that part of it, so don't bust a gut over it, however I would imagine it will come in handy for somebody else at some point.

    If only I could get the orienttopath option in either LeanTween or iTween to stop randomly flipping the meshes direction the whole movement stuff would be basically complete (bar actually creating patterns etc), that however seems to be a limitation of using 2D tweening in Unity more than anything else.
     
  5. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Lol, yup you are the only purchaser of the LeanTween Editor. So much for getting rich off of the Asset Store! ;)

    I can definitely see how moveLocal on a curve would be super handy. I am actually half-way through finishing that feature, so it shouldn't be too long before that is up.

    Ugh I know the problem, I had the same issues when I was developing my 2d game Monkeyshines, trying to get those planes to stay pointing in a certain direction can be a pain (but they don't call it Unity 3d for nothing!).
     
  6. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    GitHub has been updated with this feature! Checkout the example MoveLocalCurve-JS if you are unsure of how to use it.

    LeanTween GitHub Repo
     
  7. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    Wow that was quick! ... Thanks a bunch for this, I will get on it and let you know how I get on.

    UPDATE:

    I may end up being the bane of your existence I am afraid! So from your example it seems that I cannot just do:

    Code (csharp):
    1. LeanTween.moveLocal(gameObject, ltPath.path, 3.0f,optional);
    With a predefined path that I have set up in the visual path tool. I guess that is what I was after. In your example you have:

    Code (csharp):
    1. function moveOnACurveExample(){
    2. Debug.Log("moveOnACurveExample");
    3. var path:Vector3[] = [ltLogo.transform.localPosition,pt1.position,pt2.position,pt3.position,pt3.position,pt4.position,pt5.position,ltLogo.transform.localPosition];
    4. LeanTween.moveLocal( ltLogo, path, 3.0, ["ease",LeanTweenType.easeInQuad,"useEstimatedTime",useEstimatedTime,"orientToPath",true]);
    5. }
    So from what I can see I need to somehow get the information from the path object into a new array surrounded by 'transform.localposition'?
     
    Last edited: Jul 13, 2013
  8. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    The Visual Editor should work just fine with this new method, here is an example (I'll also try and update the Asset Store with an example soon!):

    PHP:
    #pragma strict

    public var ltPath:LeanTweenPath;

    private var 
    lt:GameObject;
    private var 
    containingCube:Transform;

    function 
    Start () {
        
    lt GameObject.Find("LeanTweenAvatar");
        
    containingCube GameObject.Find("containingCube").transform;
        
        
    loopAroundPath();
    }

    function 
    Update () {
        
    containingCube.eulerAngles.+= Time.deltaTime 10;
    }

    function 
    loopAroundPath(){
        
    LeanTween.moveLocal(ltltPath.path4.0, ["orientToPath",true,"delay",1.0,"ease",LeanTween.easeInOutQuad,"onComplete",loopAroundPath]);
    }
    Just make sure when you create your path it is centered around the 0,0,0 axis so it will start from the center of the localPostion (if that is the behavior that you want, which I assume it is).

    I hope that helps!
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Actually after looking into it, there is a bit of wonky behavior with this update, I am working on it now to resolve, but I just wanted to give you a heads up :)
     
  10. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Ok the Github page is updated, I think this moveLocal code nails it this time (at least it is working well in my tests). I am also updated the Asset Store link with some examples, including a missile launching type system similar to what you mentioned and a vehicle path simulation. Hopefully that will be helpful to you and maybe some other people, who knows maybe we can get the downloads up to 2! :p
     
  11. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    Thanks for the update .. will have a look and see where I was going wrong.

    UPDATE:

    Nope, I'm still not having any joy, if I try the new version it just doesn't do local move, it always moves the object in question to worldspace.

    I even tried just creating a new script (JS), a new path and an empty gameobject with the code you added previously and I get a massive amount of exceptions, so not sure whats going on really. Either I am being mega thick (which is highly possible)or we are living in parallel universes where it works for you and not for me!
     
    Last edited: Jul 14, 2013
  12. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    UPDATE 2:

    Nope it was me being an idiot!

    I did forget the small detail of parenting the gameobject in question to a dummy object to make sure it was moving locally! Considering I already knew that and had done it in iTween you would have thought I would have spotted that!

    And all the exceptions I was getting in your example was because I spelt one of the gameobjects wrong!! I really don't think I should be allowed to use something like Unity ... I am way too dangerous.

    Right so it seems that we are ready to go on this, if I get any other issues or think of anything else that might be useful I will ask.

    Thanks again
     
  13. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    Hello me again!

    I did think of a feature for the Visual Path tool, by default if you use one of the predefined shapes (other than a line anyway) they are always set to a certain axis (flat as if looking from above). If possible can you add an option to say by which axis they are orientated to (or just a '2D' option), so that they are facing the camera as if it were head on?

    It just saves having to go into each path and changing the values from Z to Y. Not a massive thing, but might be a time saver for some.
     
  14. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh definitely that does make sense, I will see what i can do ( I was also thinking of giving the user the ability to rotate the path using the rotate tool, so maybe that would be the right way to go about this).

    Let me know if you can think of other good predefined shapes to include.
     
  15. originalbadboy

    originalbadboy

    Joined:
    Jul 3, 2012
    Posts:
    14
    Yeah, rotating (and possibly changing the scale) of the predefined shapes would be a nice way of doing it, and makes sense in the context of the editor itself..

    A figure 8 shape would probably come in handy for some I would have thought, If I think of any more I will let you know.
     
  16. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    That's a good idea to add scaling as well. BTW there is a new update to the LeanTween Editor in the Asset Store that has two example projects:

    $ScreenShot2.jpg

    $ScreenShot3.jpg

    I hope the weapon shooting example can help your Galaga-style game!
     
    Last edited: Jul 16, 2013
  17. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Very nice work DentedPixel on the new Bezier system. This is definitely an important addition to LeanTween.

    Gotta a question:

    1. Is it possible to cancel a tween while it's in progress ? I would like to repeatedly fire off tweens but do not want it to fill up the number of allowable tweens. If I fire a new tween, I would like the currently playing tween to cancel/destroy immediately.
     
  18. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks Rocki! Yes, you can cancel a tween. When you instantiate the tween just save a copy of the id that identifies the tween, like:

    PHP:
    var tweenId:int LeanTween.movegomovePath1.0);
    Then later if you wish to cancel the tween:

    PHP:
    LeanTween.cancelgotweenId);

    // Or if you want to cancel all tweens on that gameObject
    LeanTween.cancelgo );
     
  19. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Wow, so simple... nice.
     
  20. alexmbrau

    alexmbrau

    Joined:
    Apr 28, 2013
    Posts:
    34
    Hi.
    Does anyone have "LeanTween.cs" file updated? I am using this one, but I cannot use LeanTween.alpha for a GUI.button.
    Thanks.
     
  21. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I am sorry to say, but the CS version has not been updated for about 6 months so many of the features you will find missing.

    However! Even if you are coding in C# you can use the Javascript version (just place it in your plugins directory). So you can get all the new bells and whistles. The C# version is only included for people who compile their scripts to a DLL first (which I assume is a very small percentage of developers).
     
    Last edited: Jul 19, 2013
  22. alexmbrau

    alexmbrau

    Joined:
    Apr 28, 2013
    Posts:
    34
  23. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Just updated to the latest version (v1.1) and got a bunch of critical errors :

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(54,27): error CS0117: `LeanTween' does not contain a definition for `pause'

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(59,27): error CS0117: `LeanTween' does not contain a definition for `resume'

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(68,173): error CS0117: `LeanTweenType' does not contain a definition for `pingPong'

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(142,254): error CS0117: `LeanTweenType' does not contain a definition for `pingPong'

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(142,27): error CS1502: The best overloaded method match for `LeanTween.value(UnityEngine.GameObject, string, float, float, float, System.Collections.Hashtable)' has some invalid arguments

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleCSharp.cs(142,27): error CS1503: Argument `#3' cannot convert `UnityEngine.Vector3' expression to type `float'


    My setup is : Macbook Pro, OSX 10.6.8, Unity v3.5.7
     
  24. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    You have to move LeanTween.js into the Plugins folder.
     
  25. acarter

    acarter

    Joined:
    Jul 21, 2012
    Posts:
    4
    Great library, very useful stuff! Thank you for putting a mobile-focused library together.

    I found the ability to tween colors wasn't yet included (unless I missed something, perhaps there is in fact a good reason not to include it). Either way, I was using some code of this nature to tween colors alongside my use of LeanTween, you might want to consider including whatever code you see fit to implement this functionality, I imagine less object creation and efficient use of materials would be your focus for LeanTween, at least relative to the code I've been using below within my own codebase:

    Code (csharp):
    1. public IEnumerator TransitionColor(Color originalColor, Color newColor) {
    2.     float time = 2f;
    3.     float dr = newColor.r - originalColor.r;
    4.     float dg = newColor.g - originalColor.g;
    5.     float db = newColor.b - originalColor.b;
    6.     float timePassed = 0f;
    7.     while (timePassed < time) {
    8.         float delta = timePassed / time;
    9.         SetColor(new Color(
    10.             originalColor.r + (dr * delta),
    11.             originalColor.g + (dg * delta),
    12.             originalColor.b + (db * delta)
    13.             ));
    14.         timePassed += Time.deltaTime;
    15.         yield return null;
    16.     }
    17. }
     
  26. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    +1 to have the C# version without JS dependence :)
     
  27. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks Acarter! I am glad you are finding it useful.

    I have thought of adding a color specific tweening ability, but i haven't added it yet, because it can be achieved pretty easily with the LeanTween.value function. Here is an example:

    PHP:
    LeanTween.valuegoupdateValue3Callback, new Vector3(1.00.00.0), new Vector3(0.00.01.0), 1.0);

    function 
    updateValue3Callbackval:Vector3 ){
        var 
    newColor:Color Colorval.xval.yval.);
    }
    I still may add one in the future just to make it more straightforward, but hopefully that will be enough for the time being.
     
  28. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    While the JS LeanTween file can be used to run the C# examples when it's copied to a plugins folder, I've found that it breaks MonoDevelop on my Mac so that I can't compile or debug while LeanTween is present in the project.

    I'm guessing this is some sort of issue with MonoDevelop compiling things in the wrong order (it reports LeanTween doesn't exist), but I have no idea how to correct it. Do you have any suggestions?
     
  29. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi NBurlock, I am not exactly sure I understand where it is breaking from your description. You say it works for the included C# examples? At what point does it break? I think it may be a case of Unity getting it's resources all messed up, I think it might be best to just delete LeanTween and re-download it to force Unity to re-scan the resources that are available (or maybe a restart or two of Unity could help). Unless you are trying to do something more unorthodox like compiling from the MonoDevelop Editor? I work on a Mac as well and I haven't had this issue per-say, but I have had that issue once awhile ago when it said an asset didn't exist when it clearly did...

    Also just to double check that LeanTween.js is in the Plugins folder in the root of your project. Sorry I couldn't be of more help, hopefully we can get to the bottom of your issue though...
     
  30. ultrakorne2

    ultrakorne2

    Joined:
    Apr 2, 2013
    Posts:
    6
    i am also having issue with xamarin and js. i can use the js with unity or md, but since i am using xamarin for editing it cannot open the firstpass.unityproj in the sln.
     
  31. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Okay I think I at least understand what the issue is now. I am sorry to hear people are having trouble. I only use Sublime Text to edit my code so I have never really run into this issue. What is this Xamarin? It looks neat...

    I'll try and see if there is anything that can be done. This might be the best argument I have heard for making an up to date port of the C# version, which is something I have been putting off since so much has changed it will take awhile to update...
     
  32. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Yo! Tweenbrother! :D At this point, I'd suggest you put up to date the C# version, and then continue development on that one while scrapping the JS version - as far as I know, C# plugins have no counterindications compared to JS ones, and Sublime loves C# too
     
  33. ultrakorne2

    ultrakorne2

    Joined:
    Apr 2, 2013
    Posts:
    6
    Xamarin it's basically monodevelop 4.x (new company etc..), as i find the one shipped with unity nearly unusable.

    i will keep an eye on updates, also because i was interested in leantween editor (is it compatible with the old c# version, and how outdated is that)

    i am evaluating which tween engine to use.
     
  34. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Haha, Hey Daniele! I know, it's starting to look that way, I can finally start to see why people just don't bother with Javascript plugins (not that the language itself isn't awesome, but Unity seems to have compilation issues, compiling C# first).

    I don't think I would want to ditch the Javascript version though, I really like being able to pass functions directly to the engine as callbacks without having to use Strings to refer to them, as far as I can tell there is no easy way to do this that works in both Javascript and C# :(
     
  35. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh cool, I will have to check that out. The LeanTween Editor only works with the Javascript version of LeanTween (which is compatible with C# except for the above mentioned issues).
     
  36. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    In C# you can pass functions directly (Action or Func type) without any need for strings, and it works also in JavaScript. Unless I misunderstood what you mean? :O
     
  37. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Damn, can you really do that from Javascript as well? With all my tests, I couldn't find something that was compatible with both, it looks like I will have to look into that again. Thanks so much for the help.
     
  38. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey C# users, good news, I have ported over all of the latest code to the C# version. The updated version is up on GitHub if people could check it out and make sure there aren't any bugs. I will be submitting it to the Asset Store, in the next couple of days. Thanks!

    LeanTween Github Link
     
  39. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Nice Work !
    Thanks.
     
  40. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501
    great, many thanks. LeanTween rocks.
     
  41. ultrakorne2

    ultrakorne2

    Joined:
    Apr 2, 2013
    Posts:
    6
    That was fast! many thanks. is the github version already working with the Leantween editor ?

    edit: i had a look leantween editor is in js :) will wait for an update.
     
    Last edited: Aug 6, 2013
  42. DinoMaker

    DinoMaker

    Joined:
    Aug 16, 2013
    Posts:
    1
    I also Leantween playmaker for you I'm gonna produce and distribute
    HOTTween the "PLAYMAKER" support. Currently I have been using HOTTween.
    Leantween you made a "PLAYMAKER" just want to use from.
    Many users will use Leantween into a more "PLAYMAKER" Be sure to
    Are forced to support. "PLAYMAKER" in the forum "PLAYMAKER" Leantween for the
    There are a lot of people who want to use it. Thanks gonna speak soon will be supported.

    Forum addresses playmaker
    http://hutonggames.com/playmakerforum/index.php?topic=3260.0
     
  43. dbanfield

    dbanfield

    Joined:
    Apr 20, 2013
    Posts:
    8
    Just downloaded from asset store and the ReadMe says
    "Only use the C# version if you have to! It is not as up to date as the JS version"

    Is this out of date?

    Is the C# version going to be kept up-to-date and have feature parody with the JS version? if not I will probably go with HOTween,
     
  44. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    @dentedpixel, I bought LeanTween editor. I've noticed that you can't give different colors to each path. Can you fix that?
    Another issue: When I create a path and put this object as child of another, when I move the father, the child stays on the same place. In theory, following the common usage, when I move the father node, the child should move keeping the local position to the father.

    LeanTween C# version needs: drawBezierPath
    To get it working with LeanTweenEditor

    When I change the color, it changes globally.
    Thanks!
     
    Last edited: Aug 17, 2013
  45. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi DBanfield,

    The version in the Asset Store is out of date. I have been trying to update it but Unity is giving me issues with the approval process :-/ Hopefully it will be up soon! In the meantime you can download the latest from the Git Hub page: https://github.com/dentedpixel/LeanTween
     
  46. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey DinoMaker,

    I am not sure I quite understood your message, but I am interpreting it as saying you are about offering to create support for Playmaker (with LeanTween). I sure hope that is what you are offering, let me know if I can help in any way, I am a little unfamiliar with Playmaker at the moment, so I didn't take on the full task myself...
     
  47. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Spartan,

    Thanks for the feedback, I think the color changing idea is a good one. I will try and include that in the next release. I can understand your issue with the parent object not tracking with the child... I am not sure how easy that will be to support (I'll also add that to the list).

    I have made a new version of the LeanTween editor that supports the C# version of LeanTween, I just submitted it to the store, hopefully it will be up soon...
     
  48. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    Hey dentedpixel,

    Thanks for your fast response. Yes, the issue with the parent object not tracking the child it's really important. Maybe you need to restructure the way you store the curve by using child gameobjects for each point of the curve (like Simple Waypoint System).

    Thanks for the C# version for the editor.

    Update: I made a fast solution by adding a displacement vector3 (which is optional).

    Code (csharp):
    1.     public function LTBezierPath( pts_:Vector3[], displacement : Vector3 ){
    2.         pts = pts_;
    3.        
    4.         var k:int = 0;
    5.         beziers = new LTBezier[ pts.Length / 4 ];
    6.         lengthRatio = new float[ beziers.Length ];
    7.         for(var i:int=0; i < pts.Length; i+=4){
    8.             beziers[k] = new LTBezier(pts[i+0]+displacement,pts[i+2]+displacement,pts[i+1]+displacement,pts[i+3]+displacement,0.05);
    9.             length += beziers[k].length;
    10.             k++;
    11.         }
    12.         // Debug.Log("beziers.Length:"+beziers.Length + " beziers:"+beziers);
    13.         for(i = 0; i < beziers.Length; i++){
    14.             lengthRatio[i] = beziers[i].length / length;
    15.         }
    16.     }

    And on the LeanTween move function:
    Code (csharp):
    1.     if(optional["displacement"]!=null) 
    2.     {
    3.         ltPath = new LTBezierPath( to, optional["displacement"]);
    4.     }
    5.     else
    6.         ltPath = new LTBezierPath( to);
     
    Last edited: Aug 19, 2013
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Spartan,
    I like the idea of a displacement vector, that could come in handy. You have brought up a number of good points, about the parent child issues, let me see if there is a way for it to behave more as expected, either through making the children actual game objects or some other solution.

    Thanks for the feedback!
     
  50. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Spartan,
    I went another route for adding a displacement to the path. I added a LeanTween.add method for your to add the displacement before it goes to the move method. Here is an example:

    LeanTween.move(missile1, LeanTween.add( ltPath.path,Vector3(3,4,0), 2.5, ["orientToPath",true,"delay",0.0,"ease",LeanTween.easeInOutQuad]);

    You can use the latest on GitHub to use this feature, and it will be included in the following release of the LeanTween Editor (I currently have a version pending approval so I can't include this update until the next release).

    I am continuing to think over the other feedback too.