Search Unity

  1. Unity 2019.2 is now released.
    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. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    31

    Hi Russ,

    I just tried the overshoot with a "EaseInBack" and the overshoot value does not seem to do anything. I would expect to see the change at the start of the animation.

    Version 2.30

    Thanks
     
  2. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Aholla, It should be working, you will see it in the start of the animation for that scenario like you mentioned. You may have to enter in large values to really see the difference though... try entering in a value like 200 and if you still don't see it let me know and I can investigate. I tested it locally and it is working for me, but let me know if you are still seeing a problem.

    Cheers,
    Russ
     
  3. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    Hi there!

    Is there a way to throttle / change the duration of a tween as it's playing out?
     
  4. dentedpixel

    dentedpixel

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

    You can change the time afterwards, you just use the setTime method like:

    Code (CSharp):
    1. int tweenId = LeanTween.moveX(gameObject, 5f, 2.0f ).id;
    2. // Later
    3. LTDescr descr = description( tweenId );
    4. descr.setTime( 1f );
     
  5. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    you sir, are a gentleman and a scholar!
     
    dentedpixel likes this.
  6. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    Hmmm when I update the time, it changes the current position of the tweened object.

    Is there a way to update the time so that the tweened object retains its current value but completes with the new duration?
     
  7. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    That's a good point, I have adjusted the setTime method so that it will not jump ahead, but should continue from the same spot with just a longer duration. You can get the latest change from github. Let me know if you notice any issues with it.
     
  8. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    Did it by chance not push? I'm not seeing a commit since 2 days ago
     
  9. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Darn! I had forgotten to hit the push button. I have now actually pushed that change, if you want to take a look.
     
  10. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    Yay! Ok it looks like its working great. My path lines are not rendering in the scene but I can work around that for now so no worries.

    Dude, thank you so much. Your responsiveness and quickness for me is incredible!
     
  11. DarkCooker

    DarkCooker

    Joined:
    Jan 7, 2015
    Posts:
    92
    Hi Dentedpixel

    I have not much idea how to write a curve (either bezier or other curves) between two given positions in C# code.

    e.g. I have object1 and targetPosition

    How can I write a curve let object1 moving to targetPosition naturally on Screen?

    I try the following but it looks odd to me, thanks very much ~!

    Code (CSharp):
    1.  
    2. Vector3 m1 = new Vector3((2 * object1.transform.position.x + targetPosition.transform.position.x) / 3f, (2 * object1.transform.position.x + targetPosition.transform.position.x / 3f),(2 * object1.transform.position.x + targetPosition.transform.position.x) / 3f);
    3.  
    4. Vector3 m2 = new Vector3((1 * object1.transform.position.x + 2 * targetPosition.transform.position.x) / 3f, (1 * object1.transform.position.x + 2 * targetPosition.transform.position.x / 3f), (1 * object1.transform.position.x + 2 * targetPosition.transform.position.x) / 3f);
    5.  
    6. Vector3[] path = new Vector3[] { object1.transform.position, m1, m2, targetPosition.transform.position };
    7.  
    8. LeanTween.move(object1.gameObject, path, 1.0f).setOrientToPath(true).setEase(LeanTweenType.easeInOutQuad);
    9.  
     
  12. dentedpixel

    dentedpixel

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

    You probably need to flip those two handle positions, they are reversed in the code then from what you would expect (It's quite annoying that it's this way, but I have to leave it like that for backwards compatibility). So the path would be like this instead:

    new Vector3[] { object1.transform.position, m2, m1, targetPosition.transform.position };

    Also if you just want to move between points, the moveBezier method might be a better fit.
     
  13. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Hey @dentedpixel - could you not just add new variant that has the positions corrected? (and deprecate the old style, but keep it around for a long time).
     
  14. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yeah, I like this idea, and I had been thinking about this for awhile as well. Time to sit down and do the work necessary for this fix! (the hardest part is to get the editor updated that won't break people's existing projects and allows you to do it both ways for at least for awhile).
     
  15. DarkCooker

    DarkCooker

    Joined:
    Jan 7, 2015
    Posts:
    92
    Thanks DentedPixel! It works much better.
    I can't find moveBezier this method ?
     
  16. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
    Ah yes, I didn't consider the editor extensions (I don't used them)..
     
  17. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Oh sorry, I meant moveSpline. moveBezier is the new method I will be creating to with a fixed version of the bezier ordering... at least that's the plan :)
     
  18. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    How to blink an item with LeanTween scale:

    LeanTween.scale( gameObject, Vector3.zero, 1f).setLoopPingPong().setRepeat(4); // adjust repeat if you would like it to blink multiple times (4 means it would blink twice, 2 would just be once, for ping pong always double the amount).

    I hope that helps!
    Russ
     
  19. Kavukamari

    Kavukamari

    Joined:
    Jan 2, 2016
    Posts:
    5
    I'm using LeanTween in conjunction with another spline editor, and I was having a bizarre issue where it seems as though my curves are inverted somehow



    do you know what I may have done to make this happen, or how I could fix it? I believe I've done the best I can in making sure my conversion between the formats was proper, but it seems as if all of the control points are inverted or something

    I'm only copying positional information of the objects that make up my curve, so everything should be exactly the same between the two, I would think
     
  20. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,412
  21. Kavukamari

    Kavukamari

    Joined:
    Jan 2, 2016
    Posts:
    5
    oh, I see, that works perfectly now, yeah, I had assumed the warnings were referring to the fact that you have to use the forward control point (the second one) for the first anchor, and the backward control point(the first one) for the second anchor
     
    larku likes this.
  22. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
  23. Kavukamari

    Kavukamari

    Joined:
    Jan 2, 2016
    Posts:
    5
    I had an idea while I was working on my project and I was wondering if you knew if it could be done in the system already, or potentially added later,

    Is there any way to add an OnPass(float curveTime) or OnPass(int pointID) type of event that defines a callback function that happens as early as possible once the tweening object passes by the specified reference point on the curve?

    curvetime would be the 0..1 float value along the curve you want to be the trigger point, and alternatively pointid would be the index of the anchor point you want the trigger to be, and you could hopefully add multiple events with different values and they could all fire independently of each other
     
    Last edited: Jan 16, 2016
  24. dentedpixel

    dentedpixel

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

    Yes, that does sound like a good idea, but I am not sure it would be that appropriate in LeanTween since it requires a lot of processing and there are already systems in Unity where you can get this type of behavior. Other people wanted this type of system though, that's why I am putting together an example scene for the next LeanTween Editor release of how to use the paths with Unity Trigger points, but you can try it out with this gist here: https://gist.github.com/dentedpixel/582bbaa0e0cabb2e5112

    I hope that helps!
    Russ
     
  25. Kavukamari

    Kavukamari

    Joined:
    Jan 2, 2016
    Posts:
    5
    oh, I think I understand what you mean even without looking at the example, just put a normal trigger in a place where the object will pass through, right? that's a good alternative that i hadn't thought of before, it should work perfectly well for what I wanted, I think
     
  26. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Yup, that's the idea :), feel free to look a the code though, it might help you get up and running a little quicker.
     
  27. Solid_Metal

    Solid_Metal

    Joined:
    Mar 25, 2015
    Posts:
    45
    hey, i just use this plugin today, really awesome plugin!, i use the tween color etc without hassle
    althought when i try to use move spline i got IndexOutOfRangeException: Array index is out of range.

    can you help me check whats wrong with the code?
    Code (CSharp):
    1. LeanTween.moveSpline(Sun, new Vector3[]{new Vector3(-4.23f,1.52f,0), new Vector3(0,1.52f,0), new Vector3(3.818f,0.38f,0), new Vector3(10.39f,-1.33f,0)},3f).setDelay(1f).setOrientToPath(true);
     
  28. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there,
    Thanks for checking out LeanTween, I am glad you like it so far :)

    Ooof, it looks like you found a bug, I can't believe this hasn't come up before, I guess nobody tried to move a long a spline with just two points (usually I have three or more points it passes through), but when there are only two points like this example it will break. Just a heads up the first and last points are not points it will actually pass through, but just influence the direction of the curve the spline starts and ends with (like control points). It should be able to go through two points though... I will have to fix this for a future release.

    Thanks!
    Russ
     
  29. Balvarez

    Balvarez

    Joined:
    Jul 19, 2013
    Posts:
    1
    Hi I just bought the plugin and it's really great. I'm pretty new to unity and lean tween so this might be a pretty simple question. Is there a way to set the initial rotation to a gameObject that is moving a long a path (that is oriented to the path).? The path animation seems to override any rotation i set to the object. Unfortunately it's facing the wrong direction

    http://pastebin.com/a18ZN95w

    Thanks
    Brian
     
  30. dentedpixel

    dentedpixel

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

    Unfortunately at the moment you have to make it face the right direction in this slightly awkward way:

    // Make a parent game object that you move along the path, then rotate your actual object with inside it to the right direction
    GameObject parentWithDir = new GameObject();
    this.gameObject.transform.parent = parentWithDir.transform;
    this.gameObject.transform.eulerAngles.x = 90f; // set the rotation you need it to be in;

    LeanTween.move( parentWithDir, ...);

    I hope that helps, I haven't compiled that code so some things might be slightly off, but it should be generally right.

    Welcome to Unity! And LeanTween! I am glad you are liking my plugin so far.

    Cheers,
    Russ
     
  31. adrianov

    adrianov

    Joined:
    Dec 23, 2015
    Posts:
    2
    Hi Russ,

    I've been building a project using LeanTween and I'm really happy with it so far. I'm pretty new to Unity, so I was hoping you could help me out a bit in regards to LeanTween. I'm building a tile based top down game, and I'm using LeanTween to move everything in the game. This means it is moving pretty much every single tile on my map, so a few hundred tiles. On a small map it works great and doesn't lag at all, but on a larger map, it totally stutters. I'm in the midst of trying to optimize the project and when I opened the profiler my main culprit seems to be LeanTween! Or related to LeanTween at least. Like I said, I'm new to Unity, and this is my first time using the profiler, so I'm really not sure exactly what I'm looking at. So my main CPU hog is "BehaviorUpdate", and nested inside that is "LeanTween.Update()". My thinking is that it's referring to LeanTween's calls inside my Update function, but that's just a guess. Can you shed any light on this? Any help would be greatly appreciated!

    Cheers,

    Adriano
     
  32. Berthil

    Berthil

    Joined:
    Aug 26, 2013
    Posts:
    15
    Hi,

    I found LeanTween yesterday while was searching for a tool to move my camera. Looks awesome. I downloaded it at the asset store ( free version). I watched your videos and i made some changes modifying the script, but i couldn't find the editor menu, as you shown in your videos. Is this a feature present only in the LeanTwen Editor (the paid version)?

    I am using unity 5.3.1f1 personal.
    I can see the LeanTwen menu at the Help dropdown, but not elsewhere.
    see images at the link bellow:

    https://dl.dropboxusercontent.com/u/22784211/Imagens online/2016-01-28.jpg
    https://dl.dropboxusercontent.com/u/22784211/Imagens online/2016-01-28 (3).jpg

    Thanks!

    Berthil
     
  33. dentedpixel

    dentedpixel

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

    It should be able to move a few hundred tiles just fine, but there are some factors that could make it have bad performance. Are there rigid bodies or collision objects attached to these tiles? I would disable those during the move, or remove them if they are not necessary. That would be my first guess as to what is going on there, but maybe it will not be that easy.

    I am glad you are liking LeanTween so far :), hopefully you can narrow down the performance issue...
     
  34. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi Berthil,
    Yeah the free version does not come with the visual editor, for making tweens, or paths in the Unity Editor, that is only included in the paid version (LeanTween Editor). You should be able to accomplish everything with the free version, but you will need to programmatically do everything instead of being able to easily visually do it within Unity.
     
    Berthil likes this.
  35. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    I really like LeanTween, thanks for offering it for free.

    p.s. Could you please move the Plugin files to a own folder?
     
  36. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Thanks! I am glad you like it so far. Unfortunately the Plugins folder has to be in the root of the project, it is a Unity standard, it would be great if I could put it under LeanTween/Plugins but then it wouldn't be recognized by Unityscript files. You might be able to move it into a folder of your choosing if you are only using C# scripts in your project.
     
  37. Stilghar

    Stilghar

    Joined:
    Feb 4, 2013
    Posts:
    76
    Is there any way to do something like this over a Bezier path? The Move method only allows time to be passed not speed. And I can't seem to find a way for LeanTweenPath to retun its lenght. Any ideas?
     
  38. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hi there,
    You should be able to get the length of a path, please see the PathSplinesBezier example:
    https://github.com/dentedpixel/Lean...anTween/Examples/Scripts/PathSplinesBezier.cs
    To see it in action.

    I hope that helps,
    Russ
     
  39. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Just wanted to give you a heads up that I fixed that bug you caught. You can find the fix here: github.com/dentedpixel/LeanTween (or wait a couple of days and it should be in the asset store soon)
     
  40. davidkrings

    davidkrings

    Joined:
    Feb 15, 2016
    Posts:
    12
    That actually looks quite promising!
     
  41. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    136
    Thanks but actually I don't want to see the object scales. I just want to make it blinks without a scale "transition".
    Eg:

    [Showed] ... [Hidden] ... [Showed] ... [Hidden] ... [Showed] ... [Hidden] ... etc :)
     
  42. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Ahh ok gotcha, I think something like this should work then:

    LeanTween.delayedCall( gameObject, 0.1f, ()=>{
    gameObject.renderer.enabled = !gameObject.renderer.enabled;
    }).setRepeat(8);
     
  43. LoonOfNature

    LoonOfNature

    Joined:
    Jun 20, 2014
    Posts:
    3
    Hello, I've been using your tween engine and it works nicely. Unfortunately it seems to have a conflict with part of the Google Data API dlls

    Specifically, when Newtonsoft.Json is in the project, it throws
    "Assets/Plugins/ILeanTween.cs(38,47): error CS0433: The imported type `System.Action' is defined multiple times"

    and

    "Assets/Plugins/ILeanTween.cs(81,46): error CS0433: The imported type `System.Action`2' is defined multiple times"

    On a whim I tried wrapping the offending interface in a namespace to see if that changed/broke anything different, but some searches for similar errors point to something about two different versions of .NET and Mono.

    I updated LeanTween and am currently using the newest version of Unity. The Google API version is 2.2.0.0
     
  44. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there LoonOfNature,
    Could you point me towards where I can get the asset that incorporates this version of the Google API? I can't think of what might be going wrong just by reading your description, and I was going to try and setup a test project to see if I could see what is the matter. Or if you have a test project to share that would be even better.

    Cheers,
    Russ
     
  45. LoonOfNature

    LoonOfNature

    Joined:
    Jun 20, 2014
    Posts:
    3
    I attached the fresh project with the offending DLL

    I also noticed the package I got wasn't updated since 2013, so I thought "hey, maybe it's old"

    Yes it's older, but no finding the newer packages off NuGet didn't help, they're for .NET 4 and up and from what I understand Unity's Mono is still 3.5 something something.

    The DLLs came from an installer, the first one listed here: https://code.google.com/archive/p/google-gdata/downloads

    The Newtonsoft.JSON in that one is still compatible with .NET 3.5 I think, else I'd probably be seeing different build errors when it's in the project on it's own.
     

    Attached Files:

  46. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hmm yeah, I bet it has something to do with the conflicting .Net versions.

    I found a way around it, just use the LeanTween.dll included in the project (unzip LeanTween.dll.zip), and delete the other files included in Plugins. This DLL isn't the very latest LeanTween but should be a pretty up to date stable one.
     
  47. LoonOfNature

    LoonOfNature

    Joined:
    Jun 20, 2014
    Posts:
    3
    Welp, it worked...except now A* Pathfinding is having the same problem :V

    I have a feeling many packages have similar problems with this specific DLL, and I have already gone looking around for an alternative to using the Google APIs directly(several packages are "Sort of but not quite" or "how the hell does this work"). Sorry I bothered you about this, thanks for helping.
     
    dentedpixel likes this.
  48. sirio21

    sirio21

    Joined:
    Mar 11, 2013
    Posts:
    114
    Hi! a LeanTween.newbie question why this dont work? LeanTween.scale(gameObject,transform.localScale*2, 0.5f).onComplete(end()); with itween work fine; how to call a method() after complete with LeanTween?
     
  49. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey there Sirio21,
    That was close, but it is called setOnComplete in LeanTween.
     
  50. sirio21

    sirio21

    Joined:
    Mar 11, 2013
    Posts:
    114
    ops, i correct code just before read this, thanks! :)
     
    dentedpixel likes this.