Search Unity

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. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Thanks Russ! The UIBasicsCS scene was very helpful. My mistake was trying to use GameObject while LeanTween.alpha() requires a RectTransform.
     
    dentedpixel likes this.
  2. Retrodigio

    Retrodigio

    Joined:
    Nov 20, 2014
    Posts:
    3
    Hi There,

    I've created a short script to mimic random firefly movement using LeanTween.moveSpline. The movement looks great, but appears to always jump to the wrong location at the beginning of the tween.

    Here is what the code looks like:

    Code (CSharp):
    1.  
    2. float range = 1f;
    3.  
    4. void Start ()
    5. {      
    6.         MoveSpline();
    7. }
    8.  
    9. void MoveSpline()
    10. {
    11.     int size = Random.Range(4, 10);
    12.     Vector3[] points = new Vector3[size];
    13.     points[0] = transform.position;
    14.  
    15.     for (int i = 1; i < size; i++)
    16.         points[i] = new Vector3(points[i - 1].x + Random.Range(-range, range), points[i - 1].y + Random.Range(-range, range), transform.position.z);
    17.  
    18.     LeanTween.moveSpline(gameObject, points,  Random.Range(0.5f, 1f))
    19.             .setEase(LeanTweenType.easeInOutQuad)
    20.             .setOnComplete(MoveSpline);
    21. }
    Any ideas why the movement isn't beginning from the transform's position?

    Thanks!
     
  3. Evil_Moo

    Evil_Moo

    Joined:
    Jan 23, 2014
    Posts:
    25
    If I recall correctly, the spline's first and last points are control points to manipulate the shape of the curve. I just generally duplicate the first and last actual position points to use for the control points.
     
    dentedpixel likes this.
  4. Retrodigio

    Retrodigio

    Joined:
    Nov 20, 2014
    Posts:
    3
    Thanks Evil_Moo,

    So, as in the case with my code above, would you add the transform.position to both points[0] and points[1] and then duplicate the the last point as well at points[size + 1]? Is that what you are saying or did I misunderstand?

    Thanks!
     
  5. Evil_Moo

    Evil_Moo

    Joined:
    Jan 23, 2014
    Posts:
    25
    That's correct. Or at least that's the easiest hacky way of doing it.

    I think if you want a more smoothly looping spline you would have to do something like setting the first control point to the last position point and the last control point to the first position point, but you might want to look into that further if it's necessary for you.
     
  6. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
  7. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    So Glad to hear Nims :). I will post my answer, but you are totally correct the order of the control points is kind of flipped from what you expect. I would really like to correct this, but I can't do so without messing up everyone's projects who currently have it in the flipped manner :(

    I was thinking of making move( Vector3 ) deprecated and make a new moveBezier( Vector3) that supports it in the expected manner...
     
  8. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    507
    Do you have plan to support NGUI or other 3rd libraries ? Adding a compiler directive to turn on / off support for NGUI should be cool where we can manually turn it on when needed

    What do you think ?
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    I am happy to support other developers as they work LeanTween support into their libraries, but I haven't really put the time into supporting each and every one individually. I am too busy working on new features for LeanTween itself :)

    An NGUI compiler directive is a neat idea. I haven't actually used NGUI but i hear it's a lot like the new UI 4.6 features. So possibly it would be very easy to switch between the two. Now that those Unity has it's new UI though, will NGUI not be as attractive of a solution? Has Unity sort of doomed it to irrelevance?
     
  10. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    507
    From what I see, Unity's UI is pretty in early stage, not yet very easy to use or very good in term of performance. NGUI still a better choice this time, and I doubt it's gonna change any time soon ... The question is how much the NGUI devs actually reacts to new good features people requested all time time ... Look at what Noesis GUI is doing at its current state, NGUI still have a long long way to go ... I don't know whether they will continue to do it or not, but hopefully they will do ... Anyway, I saw lots and lots people rusting to the new GUI (which does not have so many good new thing compared to NGUI, yet) ...
     
  11. malraux42

    malraux42

    Joined:
    Jan 20, 2015
    Posts:
    5
    Hello,

    I just started using LeanTween today instead of iTween (thanks for all your hard work!), but I ran into an issue using a scale animation on an object with a rigidbody. Add the following script to a Sprite, add a Rigidbody2D, and set the gravity to 0.2 for easier viewing:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5.  
    6. public class TestLeanTween : MonoBehaviour {
    7.     void Start () {
    8.         StartCoroutine(this.Grow());
    9.      }
    10.  
    11.     private IEnumerator Grow() {
    12.         float scale = 0.2f;
    13.         while (true) {
    14.             yield return new WaitForSeconds(0.7f);
    15.             scale += 0.1f;
    16.             LeanTween.scale (this.gameObject, newVector3(scale, scale, 1), 0.3f);
    17.         }
    18.      }
    19. }
    20.  
    Place the Sprite on the screen up at the top and start the game. As the object falls, the downward motion will pause during the scaling animation.

    Any ideas what might be causing this?

    Thanks,
    -scott
     
    Last edited: Mar 1, 2015
  12. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Removed post - there was no issue other than my lack of comprehension :)

    I'll replace this post with -

    I'm mass replacing iTween with LeanTween (it's so much better!!!) Thanks for your awesome work and sharing it for free - it really is good!
     
    Last edited: Feb 19, 2015
    dentedpixel and f4bo like this.
  13. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    9
    I have a question,

    Is it possible to move using speed instead of time?

    For example if we are using LeanTween.moveLocal (GameObject, Vector[] curve_points, float time)

    the same object will move at different speeds depending on curve_points (how far is each point from each other).

    Is there a way or method to move object across different curve_points at the same relative speed?

    Thanks in advance for your awesome work with LeanTween :)
     
  14. afoutsjr

    afoutsjr

    Joined:
    Aug 15, 2012
    Posts:
    7
    I am beginning to replace iTween with LeanTween in my projects, but have not found a way to use "speed" instead of "time". "Speed" can be very useful when needing to moving objects various distances . . . but at a constant rate.

    Is it possible to use "speed" instead of "time" in LeanTween?

    If not is this something that will be added?
     
  15. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Apologies if I'm just being ignorant but isn't the speed a simple function of the distance and time? Could you not just define a method that will take a speed parameter and calculate the time?

    Something like (disclaimer: totally untested and out of my head so could be complete garbage :) ):

    Code (csharp):
    1.  
    2. public static class Utils {
    3.   public static LTDescr tweenSpeed(GameObject gameObject, Vector3 to, float speed)
    4.   {
    5.       float distance = Vector3.Distance (gameObject.transform.position, to);
    6.       float time = distance / speed;
    7.       return LeanTween.move (gameObject, to, time);
    8.   }
    9. }
    10.  
    And use like:

    Code (csharp):
    1.  
    2. private void myFunctionSomewhere()
    3. {
    4.   Utils.tweenSpeed(gameObject, moveToThisObject.transform.position, speed);
    5. }
    6.  
    Would that work?


    Of course there is always:

    http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html

    But using tweens tends to make more readable code (IMO).
     
  16. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    9
    @larku Yes indeed I can use a function like the one you propose to calculate the time depending on the distance.

    It was just a question if somehow that was integrated in LeanTween

    :)

    Either way thanks !!!!:)
     
  17. AntFitch

    AntFitch

    Joined:
    Jan 31, 2012
    Posts:
    243
    This is a very nice tool. I think I found a bug with the new recttransform support (or I need to do something). Here's the scenario:
    1. I use LeanTween.move(rectTransform, endPos, time) to move a uGUI element from (-600f, 920f, 0f) to (-600f, 520f, 0f)
    2. The uGUI element moves from Y=520 to Y=920 (to correct location from the correct location).
    3. I use LeanTween.move(rectTransform, endPos, time) to move a uGUI element from (-600f, 520f, 0f) to (-600f, 920f, 0f)
    4. The uGUI element moves from Y=2031 to Y=520. (from incorrect location to correct location).
    Any thoughts? I tried clearing out tweens between moves, but this did not help.

    [Canvas: Screen Space = Overlay, Pixel Perfect, Sort Order = 0]
    [Canvas Scaler: UI Scale Mode = Scale with screen size, Reference Resolution = 1024x768, Screen Match Mode = Match Width or Height, Reference Pixels = 1]
     
    Last edited: Feb 27, 2015
  18. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Not offering any help, but dentedpixel may want to know some details about your canvas so he can reproduce your issue, ie, is it screen or world space? What is the canvas size etc..
     
  19. AntFitch

    AntFitch

    Joined:
    Jan 31, 2012
    Posts:
    243
    Thanks, larku, I've updated my question with canvas info.
     
  20. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    572
    Today I tried to build my game with Windows Store 8 Apps and I couldnt because of these errors:

    Assets/LeanTween/LeanTweenExamples/Scripts/ExampleJS.js(172,27): BCE0018: The name 'LTDescr' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuExampleJS.js(7,25): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuExampleJS.js(8,25): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuExampleJS.js(9,25): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuExampleJS.js(10,25): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Could not load file or assembly 'SyAssets/LeanTween/LeanTweenExamples/Scripts/ExampleJS.js(171,20): BCE0018: The name 'LTDescr' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuExampleJS.js(12,28): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MenuSimpleJS.js(3,19): BCE0018: The name 'LTRect' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/MoveLocalCurveJS.js(11,20): BCE0018: The name 'LTSpline' does not denote a valid type ('not found').
    Assets/LeanTween/LeanTweenExamples/Scripts/SlideImageIn.js(5,24): BCE0018: The name 'LTRect' does not denote a valid type ('not found').

    Any fix/solution?
     
  21. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Not sure why you'd have that error. Do you have the LeanTween.cs file in your project under the Assets folder somewhere?

    Regardless, all these errors appear to be in the examples - unless you need them for some reason I'd delete that entire LeanTweenExamples folder from your project.
     
  22. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    572
    I know I have just delete them but the default project should not have errors.
     
  23. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    Awesome assets dentedpixel, just left you a 5 star review! I am trying to make a camera follow some path but when there is some extreme curve sometimes the transform is rotated 180 degrees on the opposite z axis from the previous orientation when using setOrientToPath(true). Is there any way to block rotation around certain axis so that it still orient toward the path but doesn't make extreme rotations like this?

    Or even better, is there a way to control the rotation with the points used in the splines?
     
  24. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    Turn out the issue is not with LeanTween but with the Unity LookAt function, that when 2 points are somewhat aligned arbitrary make 180degrees unnecessary turns. For the moment I will use some targets outside the path to avoid this issue.
     
  25. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    I'm new to LeanTween

    I'm trying to set a public Ease Type variable in LeanTween so I can choose Ease Types from the Inspector

    With iTween I just do it like this

    Code (CSharp):
    1. public iTween.EaseType easeType;
    not sure how to do this with LeanTween
     
  26. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    It's almost exactly the same :)

    Code (csharp):
    1. public LeanTweenType easeType;
     
    graviton likes this.
  27. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    What is LeanTween's equivalent to iTween's "oncompletetarget" property?
     
  28. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    There is no need (and would not make sense) for an oncompletetarget since LeenTween does not take a method 'name' it takes a direct reference to the target (it calls the actual method you pass - it's a pointer/reference to it) or an Action if you prefer.

    As such, you can use a delegate instead of a method like:

    Code (csharp):
    1. LeanTween.move(gameObject, newPos, 1.0f).setOnComplete( delegate () {
    2.   //
    3.   // Do on complete stuff here.
    4.   //
    5. });
    Or you can pass a reference to the method you want to call. If you need to call a method on another class/instance do it like:

    Code (csharp):
    1. LeanTween.move(gameObject, newPos, 1.0f).setOnComplete(objectIWantToInvokeMethodOn.TheMethodToInvoke);
    Another example:
    Code (csharp):
    1. LeanTween.move(gameObject, newPos, 1.0f).setOnComplete(otherGameObject.Destroy);
     
    graviton likes this.
  29. Trav3l3r

    Trav3l3r

    Joined:
    Sep 16, 2014
    Posts:
    58
    I was wondering if there's a bug with moving rectransforms in vertical directions?
    I have a panel with menu items that I want to move outside the screen, but I can only get it working in a horizontal direction.

    For instance, this snippet moves the panel to the right, but not down.
    Code (CSharp):
    1. LeanTween.move(panel, new Vector2(480,-800), 0.75f).setEase(LeanTweenType.easeOutQuart);
    (vector2 or vector3, either wont work)

    This behaviour can also be seen with the pause button in the 4.6 example scene.
    Code (CSharp):
    1. pauseWindow.anchoredPosition3D += new Vector3(0f,200f,0f);
    2. LeanTween.move( pauseWindow, pauseWindow.anchoredPosition3D + new Vector3(0f,-200f,0f), 0.6f).setEase(LeanTweenType.easeOutSine).setDelay(0.6f);
    This snippet does not tween between the given values, but immediately snaps to a set value.

    Can anyone confirm this?

    Thanks.
     
  30. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    You're awesome, thanks for this
     
  31. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Totally welcome!
     
  32. Trav3l3r

    Trav3l3r

    Joined:
    Sep 16, 2014
    Posts:
    58
    In case anyone is interested, I'm using this :
    Code (CSharp):
    1. LeanTween.value(gameObject, new Vector2(480,0), new Vector2(0,0), 0.75f).setEase(LeanTweenType.easeOutQuart).setOnUpdateVector2((Vector2 val) => panel.anchoredPosition = val );
    2.  
    until this issue has been cleared up
     
  33. Teo

    Teo

    Joined:
    Oct 31, 2009
    Posts:
    564
    Any plans to update this for Unity 5?
     
  34. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Just curious, what would you expect to be updated? I've built my existing game (from 4.6.3) with U5 and LeanTween worked perfectly (for all the bits I use)..
     
  35. Teo

    Teo

    Joined:
    Oct 31, 2009
    Posts:
    564
    Really?

    this:
    Assets/Plugins/LeanTween.cs(1259,103): error CS1061: Type `UnityEngine.Component' does not contain a definition for `material' and no extension method `material' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

    and rest of 26 errors.
     
  36. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Ahh, right sorry my bad. Unity's project updater would have amended the deprecated/removed api calls during my project update.

    I think there is a way to manually run the project updater to fix that for you - or you could just fix them yourself, it's mostly replacing calls to the old accessors to GetComponent<missingComponentType>() in most cases.

    I'd just post my corrected version here but it's not my asset to do that with :(

    Edit: I couldn't find a way to manually run the update script - but if you create a project into 4.6.x and then add LeanTween then close and reopen it in Unity 5 it'll update it for you. That'll get you a working LeanTween.cs file you can use until its been officially updated.
     
    Last edited: Mar 8, 2015
  37. Codemonger

    Codemonger

    Joined:
    Dec 12, 2013
    Posts:
    30
    I switched to DF Tween Pro some time ago for the use of Extension Methods because I found them extremely handy and verbose. I find DF Tween has a lot of stutters even when compared to Lean Tween side by side. Now I appreciate Lean Tweens speed and simple straight forward syntax more than ever so I have switched back to Lean Tween. Amazing work !

    Any chance of implementing Extension Methods as an extra layer of syntactic sugar or would that be awkward because the game object is passed instead of the transform and maybe cause to much method pollution on the GameObject ? Or maybe would it be possible to attach extension methods to the transform and inside the method pass the transform.gameObject ...

    Any thoughts on this ?
     
  38. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    I agree - LeanTween is the premier tool for the job and the author (dentedpixel) should be very proud of his work and I'm very grateful for it being free!

    Regarding extension methods - I would actually suggest adding these yourself in your own static class somewhere..

    1. It provides your own abstraction away from the actual implementation of LeanTween and enables you two switch which tweening implementation you use by just changing that one class - too some degree depending on how it's built and how you form the method signatures.

    2. It's totally trivial to add them, it would take just minutes to add all the extensions you'll need. I assume you know how to do this so I won't patronise you by explaining it. If you don't though, just say and I'll give you some quick examples on how to do this - even throw me a call to LeanTween and I'll make the extension method for it as an example.

    3. I'm not sure it'd be great use of dentedpixel's time. As you said they are just syntactic sugar but will add additional maintenance effort to dentedpixel's workload - I'd vote for him to add additional cool features to LeanTween rather than spend effort on sugar (just my opinion, and I'm not projecting that onto everyone else - you may rightfully feel different)
    My 2bit opinion :)
     
  39. Teo

    Teo

    Joined:
    Oct 31, 2009
    Posts:
    564
    @larku I dont have 4.6 anymore, only 5 testing new stuff.
     
  40. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Sent you a private message.
     
  41. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Hey amaranth,

    I think your issue may be that you need to use LeanTween.moveLocal(....) rather than LeanTween.move(....)

    EDIT: Ok, so maybe not.. Seems I'm also having trouble getting consistent results with rect transforms.

    EDIT2: Correction, things seem to work just fine using LeanTween.move(rectTransform, ....) - I had issues with some code logic and was not an error with LeanTween. moveLocal is most likely not the solution for you - it doesn't do what I expect it would!
     
    Last edited: Mar 10, 2015
  42. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    LeanTween currently have a very critical bug that take me half a day to figure out, I thought it was my fault but not, it's about method cancel() of LTDescr.

    In my situation, I spawn several objects and use moveSpline() to move them along several different paths.
    While they are moving and not yet finished, I stop them all using method cancel() of LTDescr. Every object have themselves reference of LTDescr to make sure they don't reference to the same LTDescr of course. For example something like this:

    Code (CSharp):
    1. public class myClass : MonoBehaviour {
    2.     LTDescr _tween;
    3.  
    4.     public void moveMe() {
    5.         ......
    6.         _tween = LeanTween.moveSpline(...);
    7.     }
    8.  
    9.     public void stopMe() {
    10.         if(_tween != null)
    11.             _tween.cancel();
    12.     }
    13. }
    Then I call moveMe() to move them again then there is a bug that the method LeanTween.moveSpline(...); will return a LTDescr that is using by another one. Thus now there are 2 object using the same LTDescr at the moment, and the later object will actually control the LTDescr, so the first one will stop moving.

    if I change _tween.cancel() to LeanTween.Cancel(gameObject); then it works fine.

    By the way LeanTween's performance is very good.
     
    Last edited: Mar 13, 2015
  43. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Hey ericweiss,

    You didn't explain what the bug is - you state you call LTDescr.cancel() but you didn't say what was wrong with that.
     
  44. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    Hi, I've just modified my post
     
  45. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Looking at the code it appears that LeanTween intentionally reuses old LTDescr objects (once they have been 'cancelled' they are free to be reused).

    It keeps a pool of LTDescr objects and does not allocate new ones - as such, once you call cancel on one it is then invalid and all references to it should be dropped.
     
    Last edited: Mar 13, 2015
  46. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    That's the point, in this case _tween.cancel(); break that rule, and LeanTween.Cancel(gameObject) still work correctly.

    You will see that when doing a test like I said
     
  47. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    I just make myself clearer by changing this : "Then I call moveMe() to move them again then there is a bug that the method LeanTween.moveSpline(...); will return a LTDescr that is using by another one."


    "
     
  48. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Hi Russ,

    I haven't updated Leantween for quite a while, but when I updated it today the Orient2Path2d function was not working properly with the new version. I found out what the cause is, so if you could fix it up for future versions that'd be geat - thanks.

    The change required is easy:
    In lines 595 & 605 & 785 & 795 (place2d and placeLocal2d) can you please change:

    transform.eulerAngles = new Vector3(0, 0, angle);
    to:
    transform.eulerAngles = new Vector3(0, 0, angle-90);

    Thanks Russ.
     
  49. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    Hi, it seems that the latest version 2.25 and even earlier version 2.24 has the bug that does not call oncomplete on start when I use like this for example :

    Code (CSharp):
    1. LeanTween.moveLocalX(gameObject, 5, 5).setOnComplete(Complete).setOnCompleteOnStart(true);
    2.  
    3. or
    4.  
    5. LeanTween.moveLocalX(gameObject, 5, 5).setOnComplete( () => {
    6.             Debug.Log("on complete move local X");
    7.         }).setOnCompleteOnStart(true);
    It would be great to have suggestion about what to fix and where to fix as I am close to next delivery time.
     
    Last edited: Mar 18, 2015
  50. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    Hi, is there a way to use LeanTween.moveSpline as speed based rather time based like iTween or DOTween does.