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

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Aholla,
    I have added options to these methods where you can control the overshoot (for back and elastic), and the period (for elastic only).

    The docuementation for it is here:
    http://dentedpixel.com/LeanTweenDocumentation/classes/LTDescr.html#method_setOvershoot

    It works like:
    Code (CSharp):
    1. LeanTween.moveX(gameObject, 5f, 2.0f ).setEase( LeanTweenType.easeOutElastic ).setOvershoot(2f).setPeriod(0.3f);
    You will need to grab the latest from Github though to use this latest feature.

    Thanks!
    Russ
     
  2. Deleted User

    Deleted User

    Guest

    Awesome! Thanks :)
     
    dentedpixel likes this.
  3. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81


    Brilliant!!!!!!!!!!! THanks!
     
    dentedpixel likes this.
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Aholla,
    I said I had put the changes up on Github, but I had forgotten to push my changes. The new setOvershoot and setPeriod methods are up on github now .
     
  5. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Gee Russ, I'm not sure we can put up with this kind of mistake!!! I'm going to do all my tweening by hand until you lift your game!!!!
     
    dentedpixel likes this.
  6. festival

    festival

    Joined:
    Feb 3, 2011
    Posts:
    80
    Noticed that when I fire the first LeanTween.scale tween it needs >8ms in LeanTween.Update()
    only the 1st time.

    Then I see a very noticeable lag on an Android Nexus 7 device.

    Can I prevent this 1st time tween lag?
     
  7. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Festival,
    I can't think of why LeanTween would be causing that first-time lag. I have a feeling it might be things involved in the Unity engine, possibly the first time an object is set to something other than 1 there is some overhead involved in the engine. I would suggest setting it to something close to 1f on Awake like:

    void Awake(){
    transform.localScale += new Vector3(0.001F, 0.001F, 0.001F);
    }

    This should get that overhead out of the way, so you don't get any lag that first time. Let me know if this doesn't work though, and I can dig into it more.

    Cheers,
    Russ
     
  8. festival

    festival

    Joined:
    Feb 3, 2011
    Posts:
    80
    Will try this.

    Currently I just made a dummy LeanTween.scale at Awake() which might
    also cache the transform.localscale.

    Btw I cached the transform in my code too.
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Great, let me know if this doesn't solve the issue. Then there actually might be a first-time performance issue in LeanTween and I will try and dig deeper into it.
     
  10. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    Hey! I am using LeanTween for my current project. Very useful and fast tween engine indeed! :D

    Is there a function like "PunchScale" function iTween has? Or it has different name?

    Thanks!
     
  11. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Elmar,
    I am glad you are finding it useful and fast :)
    There is something similar in LeanTween. You can punch like this:
    Code (CSharp):
    1. LeanTween.scale(this.gameObject, Vector3.one*3f, 1.0f).setEase(LeanTweenType.punch);  
     
  12. mk22

    mk22

    Joined:
    Feb 1, 2015
    Posts:
    51
    Hey,

    I'm using LeanTween. I like it. Next month I'm going to buy LeanTween Editor, but for now I have to use it by code in free version.
    I don't know if I use it 100% properly.
    Usually my object doesn't move through bezier path with fixed speed (and I want fixed speed). In some parts of my path ( I tried on few different paths) my object moves faster.
    For example:


    (This path is made by using 11 points). My object is moving faster in selected parts.
    (when I tried on different paths, object moves faster at the end of the path)

    My code:
    Code (CSharp):
    1.  
    2. public float iter = 0;
    3. public int direction = 1;
    4. public float speed = 0.5f;
    5.  
    6. //I'm colling this function in Update()
    7. public void move()
    8.     {
    9.         cr.place2d(myObject.transform, iter );
    10.  
    11.         if ((iter + Time.deltaTime * speed * direction) < 0.0f || (iter + Time.deltaTime * speed * direction) > 1.0f)
    12.           direction = -direction; // I want to my object turn back at the end of the path
    13.  
    14.         iter += Time.deltaTime * speed  * direction;
    15. }
    16.  
    Do you know why my object moves through the path in different speed?
    Thanks
     
    Last edited: Jun 15, 2015
  13. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    You don't appear to be using LeanTween at all in that code - have you looked at the LeanTween examples?
     
  14. mk22

    mk22

    Joined:
    Feb 1, 2015
    Posts:
    51
    It was only part of my code.

    'cr' is public LTSpline cr;
    Code (CSharp):
    1. cr = new LTSpline( pos); // pos is array where I have positions of  my points
    I was only using move() function to push my object through the path.

    I change my code to:
    Code (CSharp):
    1. LeanTween.moveSpline ( myObject, cr.pts, time).setEase (LeanTweenType.linear);
    instead move() function;

    Now is much more better, but speed isn't 100% the same on whole path. Is it normal?
     
  15. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    dentedpixel likes this.
  16. mk22

    mk22

    Joined:
    Feb 1, 2015
    Posts:
    51
    Thanks. I replaced LeanTween files from my project (I had it from AssetStore) onto files from https://github.com/dentedpixel/LeanTween .
    I didn't change my code.
    I don't know it will fix all this situations with different speed, but I tested it with some of my paths and now it looks more smoothy. (I had problem esspecially at the ends of path. Object moves faster there and it was weird)
     
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yup like Larku said, I have recently fixed up that bug where it can move at different speeds for Splines (beziers actually always had this fix). Let me know if you continue to see any issues. I will try and get this into the Asset Store version shortly...
     
  18. mk22

    mk22

    Joined:
    Feb 1, 2015
    Posts:
    51
    Ok, thanks.
     
  19. CaptainKirby

    CaptainKirby

    Joined:
    Dec 12, 2011
    Posts:
    36
    Hi.
    2 things:
    1 Can't believe i haven't heard of this before.
    2. Can't believe that this is free. Nuts.

    Great applause towards your general direction!
     
  20. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hello! 2 things:
    1. Thanks, Help get the word out ;)
    2. You're Welcome!
     
  21. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Indeed!
     
  22. CaptainKirby

    CaptainKirby

    Joined:
    Dec 12, 2011
    Posts:
    36
    Will do!
    I actually have a question now that I've used it a bit:
    I am moving along an array of vectors with movespline
    Code:
    LeanTween.moveSpline(obj, pathV, 1.5f).setEase(LeanTweenType.linear).setOrientToPath(true);

    And while it works, It seems that it does not want to move to the last array vector for some reason. This could very well be me making an error, but I just want to make sure I am not missing anything. Is there something that you know of that could cause this, in regards to leantween?

    Also I have another question, I seem to not be able to find it, but is there a way to see the length of a spline? I wish to move an object along it, by a speed rather than a set duration(the length of the spline might vary).
    Best regards!
     
  23. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Strange Unity 5.1.1 32 bit build error -The type or namespace nameUI' does not exist in the namespaceUnityEngine in LeanTween.cs
    Anyone else experience this?
    If I open compile the identical project using 64bit 5.1.1 build, no errors.
     
  24. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Hello Dented Pixel,

    Thanks for this great asset! I have a question about it; I would like to camera to follow my player with leantween. I tried to do with Leantween.move but if this function is called too much during playing, leantween breaks. Which function should i use for camera follow?

    Thank you so much!
    Have a good day!
     
  25. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Are you by any chance calling LeanTween.move(gameObject) very often without calling LeanTween.cancel(gameObject)?

    If you have a tween running on an object and you want to override/update that tween you need to cancel the old ones first.

    Just taking a shot in the dark here.
     
  26. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    It seems good but this time, it stops working because of canceling the move all the time. I am going to try to use it under another void.

    Here is what i do;
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. LeanTween.cancel(cam.gameObject);
    5. LeanTween.move( cam.gameObject, newVector3(transform.localPosition.x, 3.85f, -3.03f), 2f).setEase(LeanTweenType.easeInOutCubic);
    6. }
    7.  
     
  27. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    You're calling a tween that should only be called once every frame. Move it out of the Update method.
     
  28. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    I moved it out from update method. I put it in 'void OnTriggerEnter(Collider other)' . It calls from trigger when the character triggers the box which is located in left or right or middle part of the screen. But, i still have broken leantween.. It doesn't work well in trigger method either. What kind of method can i use except update and trigger? And i should always update the position of the player and let the leantween know about it to move the camera through that position with leantween. How can i do that?

    Thanks for interesting!
     
  29. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
  30. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Trying to simply tween the 'brightness' of a single object. Since they have emissive materials I think this means 2 separate tweens, one for the emissive property and one for the actual object. Can anyone help?
     
  31. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Code (CSharp):
    1. LeanTween.value( myBrightnessGameObject, TweenBrightness, myStartBrightness, myTargetBrightness, myTweenDuration );
    2.  
    3. public void TweenBrightness( float brightnessValue ) {
    4.      myEmissiveMaterialBrightnessProperty = brightnessValue;
    5.      myOtherBrightnessProperty = brightnessValue;
    6. }
    7.  
    Obviously, you need to plug in your own variable names in place of those that start with "my."
     
  32. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    Hi great plugin, I've moved from iTween to use this and I am very happy with it. There is one thing I want to do which I can't quite figure out.

    What I'm trying to do is the following:
    - Move from point a to point b
    - Move from point b back to point a
    - Hide object for 5 seconds
    - Repeat

    This leads me to my question, when is onComplete called if the loop type is set to PingPong and repeat is -1? Is it even called?

    Thanks!
     
  33. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    Forgive me if I am just missing it, but I have searched around and can't seem to find an answer:
    Does LeanTween support the ability to tween volume?

    You can do this easily with TweenLite doing the following:
    TweenLite.to(mc, 1, {volume:0});

    I couldn't seem to find something similar with LeanTween.
     
  34. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    You can tween any value:
    Code (CSharp):
    1. LeanTween.value( myAudio.gameObject, v => myAudio.volume = v, startVolume, endVolume, timeToFade );
     
  35. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I don't think so. Could you set up your own little sequence?

    Code (CSharp):
    1. public IEnumerator Movement() {
    2.     LeanTween.move( objectToMove, destination, time ).setRepeat(1).setLoopPingPong().setOnComplete( () => HideObject( objectToMove ) );
    3.  
    4.     yield return new WaitForSeconds( time * 2 + 5 );
    5.  
    6.     StartCoroutine( Movement() );
    7. }
    I think the LeanTween Editor might have tools for chaining together tweens, but I haven't checked it out.
     
    SimteractiveDev likes this.
  36. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    I didn't think about doing it that way, I'll give that a go, thanks!

    I think been able to know when a pingPong has completed would be beneficial though.
     
  37. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi, im having trouble with my tweens. I have 4 game objects in a list which I am iterating over and calling a method on each with triggers a tween. The problem is that sometimes (60%) the first tween does not seem to work. Any ideas?

    Code (CSharp):
    1. // ScriptA
    2. for ( int i = 0; i < gameButtons.Count; i++ ) {
    3.             GameButton button = gameButtons[ i ];
    4.             button.animationOutCompleteEvent += OnButtonAnimOutComplete;
    5.             button.Hide();
    6.         }
    7.  
    8.  
    9. //-----------
    10. // GameButton Script
    11.  
    12. public void Hide() {
    13.     float duration = 0.2f;
    14.     float delay = 0.1f ;
    15.     float destScale = 0.0f;
    16.  
    17.     Debug.Log( "This always fires" + this.name );
    18.  
    19.     LeanTween.scale( star.gameObject, new Vector2( destScale, destScale ), duration )
    20.         .setEase( LeanTweenType.easeOutBack )
    21.         .setDelay( delay )
    22.         .setOnComplete( () => {
    23.             Debug.Log( "This sometimes does not fire" + this.name );
    24.             if ( animationOutCompleteEvent != null ) {
    25.                 animationOutCompleteEvent( this.gameObject );
    26.             }
    27. } );

    [EDIT] - So I found the cause. In an other script I had another tween that was triggered at the same time. For this one I was saving the returned value from the tween and canceling it before. Removing this fixed my other tween problem. I guess it was cancelling all tweens?
    Code (csharp):
    1.  
    2. LTDescr savedTween;
    3.  
    4. void DoTween() {
    5.     if( savedTween != null ) {
    6.         savedTween.Cancel();
    7.     }
    8.     savedTween = LeanTween.move(go, 1, 1);
    9. }
    10.  
     
    Last edited: Aug 19, 2015
  38. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi,

    I'm trying to tween between a series of points. Can lean tween just move from point to point of does it have to move through a bezier with control points. There reason I ask is because I have tried several bezier curve libraries and Lean tween does not follow any of the curves correctly. So if i could just mve from point to point that would be great.

    Thanks.


    [EDIT] Just found this post: http://answers.unity3d.com/questions/562947/leantween-strange-sequence-of-bezier-control-point.html

    Seems i had the control points the WRONG way round.... :( All works now.

    Perhaps in the docs it could be highlighted this is the the wrong way round.


    Thanks
     
    Last edited: Aug 20, 2015
  39. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi
    Keep uncovering the power of LT. Soon will be using the editor to do ALL my camera motion and bezier tweens.
    My question
    Having a problem both moving AND rotating a gameObject at the same time
    Can both a move and a rotate be combined? Or do I need to overwrite with a separate tween?

    Here is my existing code. I want to add a 30 degree rotation to the left

    LeanTween.move(gameObject, new Vector3(1.0f,4.5f,-2.0f), 4.0f) .setEase( LeanTweenType.easeInQuad );
     
  40. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Heya Ecobach,

    I only see a move command here, but you can add a rotate by doing something like:

    LeanTween.rotateAround( gameObject, Vector3.forward, -30f, 4.0f).setEase( LeanTweenType.easeInQuad );

    Best of luck with the Editor! Let me know if you need any help with that.
     
  41. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi is there any way to use "setFrom" and "setDelay" so that the "setFrom" is applied immediately.

    Eg I would live to fade in a button after 1 second. I set the from alpha to zero but this is only applied when the tween starts. I have to manual set the color/alpha myself before the tween and ignore the "setFrom". I use a lot of delays in my tween code which means I can't really use the setFrom but would love to.

    Thanks!
     
  42. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there Aholla,
    Yeah the way the setFrom is intended to be used is to have that action happen only at the start of a tween. If you would like to have it happen immediately, you can do a separate tween to accomplish that like:

    LeanTween.alpha(gameObject, 0f, 0f);
    // passing in a time of 0 will make it happen immediately (or rather on the very next OnUpdate call)

    I am not sure if you were looking for something else, but I hope that helps,
    Russ
     
  43. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Ah okay thats cool, I was just worried about startign a tween with a zero duration but I guess you take care oif that. Thanks!
     
  44. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    So I just tried it and nothing happens, no tween. I think this is what happened to me before when I set the duration to "0". If is set it to "0.00001" it works but you get a flicker. If I set it to "0" its as if the tween does not exist.

    Code (csharp):
    1.  
    2. LeanTween.scale( gameObject, Vector3.zero, 0.0f ); // does nothing
    3. LeanTween.scale( gameObject, Vector3.zero, 0.0001f ); // works but has a slight delay
    4.  
    Thanks.
     
  45. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Having problems with setOnCompleteParam
    Followed this example exactly

    https://github.com/dentedpixel/LeanTween/issues/8
    Here is my code
    I get an 'error CS1525: Unexpected symbol `['' on the line where I first define setOnCompleteParam.

    So I tried removing the square brackets from delOff and this just leads to other errors!

    private void signalOn(float delOn,float delOff){

    Debug.Log("4 ASSERT signalOn delOff="+delOff);
    LeanTween.value( gameObject, 0f, 0.9f, 0.1f).setOnUpdate( (float val)=>{

    _flashlight.intensity=val;
    } ).setOnComplete( signalOff).setDelay(delOn).setEase( LeanTweenType.easeInQuad ).setOnCompleteParam( [delOff] as object[] );
    }


    private void signalOff(object args){
    float onTime=(float)args[0];
    LeanTween.value( gameObject, 0.9f, 0f, 0.1f).setOnUpdate( (float val)=>{

    _flashlight.intensity=val;
    } ).setOnComplete( signalNext).setDelay(onTime).setEase( LeanTweenType.easeInQuad );

    Debug.Log("5 ASSERT signalOff onTime ="+onTime);
    }
     
  46. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there,
    Yeah I have run into that issue before it's sort of annoying. Because delOff is a float which is a primitive it can't be an "object". This is the code I have used to get around that in the past, which converts it into a string object and back:
    Code (CSharp):
    1. LeanTween.delayedCall(0.05f, enterMiniGameStart).setOnCompleteParam( new object[]{""+delOff} );
    2.  
    3. void enterMiniGameStart( object val ){
    4.         object[] arr = (object [])val;
    5.         float delOff = float.Parse((string)arr[0]);
    6.         Debug.Log("finally back into the right format delOff:"+delOff);
    7.     }
     
  47. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Hi, I've been looking through your API to find a way to auto complete a tween but it doesn't look like that is possible. Am I missing something? Is there a way to instantly finish a tween that is in progress?

    The best I can come up with is to write a custom onComplete that also auto-finishes the tween and then call cancelAll while forcing the onCompletes to be called. Is that the best/only way?
     
    Last edited: Sep 7, 2015
  48. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Doh, I didn't realize a tween with time value of zero would not complete, I guess in the past I have just made it a very small time value like you tried. I have pushed an update that accommodates tween values with a zero time. Please check out the latest on Github and let me know if that is still causing a flicker.
     
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there Velvety Couch,
    While I was looking to explain a simpler way I realized it could be made much simpler (and I have also had someone else say they needed this functionality). I have added a second parameter for the LeanTween.cancel( id, callOnComplete) method, so you can also call the onComplete while canceling. You can get that update on github.

    BTW, I just picked up your OddBalls game, it looks fun. I can't wait to play it.
     
  50. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Awesome, thanks DentedPixel! :)