Search Unity

DOTween (HOTween v2), a Unity tween engine

Discussion in 'Assets and Asset Store' started by Demigiant, Aug 5, 2014.

  1. Nemial

    Nemial

    Joined:
    Feb 25, 2014
    Posts:
    16
    I tried that and it seems to stop the progression at a snails pace, however it seems to start off horrendously slow and then exponentially rush to the finish at the end, i do not doubt that it reaches the desired destination in the time given, however it loses the smoothness of a constant speed throughout without any easing functions attached to it.

    So really my question at the start of this exchange should have been is there a way to constantly change the end value while maintaining the constant speed of the tween? or am i hoping for what is not currently possible with the way the tweens operate?
     
  2. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Achieving true constant speed with something like that is not possible, unless you also take into account also the difference between the initial distance and the new distance (since the dragged object might be, for example, being dragged upwards) when calculating the new duration, but if you set the ease to linear it will look way better, give it a try:
    Code (csharp):
    1. _trackTween = _displayCopy.transform.DOLocalMove(transform.localPosition,0.5f,false).SetEase(Ease.Linear).OnComplete(()=>{GameObject.Destroy(_displayCopy);});
     
  3. Nemial

    Nemial

    Joined:
    Feb 25, 2014
    Posts:
    16
    That did the trick and even other easing options worked quite nicely as well such as OutCirc or OutCubic, obviously some of them do not work as normal given the circumstances but if you want something a bit more organic and lively than linear those two work fine.
     
    KarolRG likes this.
  4. fionivar82

    fionivar82

    Joined:
    Oct 15, 2014
    Posts:
    4
    Thanks for the heads up about setting the looping!

    However I am having troubles wrapping my head around this cube rolling business. Essentially what I want it to do is roll over its edge (90 degrees at a time would be grand which is what I had thought DOLocalAxisRotate would do for me), end over end.

    The result I get is a rolling cube facing the vector I've set via click, but the rolling motion resets to the original - is looping not the method I should use? To clarify, the aim I have is to have it roll over each of the four faces.
     
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @fionivar82 Oh I thought you were using a Restart loop because your cube had no different faces. The regular loop is set to LoopType.Restart, which means it will restart with each loop cycle. If you want it to increment instead (thus going over all the faces in your case), set it as LoopType.Incremental and it'll do the trick :)
    Code (csharp):
    1. transform.DOLocalAxisRotate(newVector3(90,0,0), 1).SetLoops(10, LoopType.Incremental);
     
  6. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    @Izitmee Thanks for the updates. Maybe you have a timeline for DOTween development? I mean when do you think it would enter a Beta or RC phase?
     
  7. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    I would've actually already moved to RC phase if I hadn't decided to move the path plugin into the free DOTween version. The only alpha part is now the path plugin, while all the rest is Beta. Path plugin might take a little while to move to Beta, because I'm making sure it will also work with Simple Waypoint System correctly and with the path editor I'm building for the Pro, so I have to complete the latter too. All in all, I hope to give a big push next week and move everything officially to Beta, then plan for RC.
     
    Baroni likes this.
  8. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    Hello Izitmee,

    A little thingy;

    When i start a Tweener including .SetEase(someEaseVar), where someEaseVar doesn't have a default value set, i don't receive any warning / error from DOTween.
    I also did logging with default and error setting but no result either.
    The result when running this code:
    1. Tween is started,
    2. OnStart callback is called
    3. After that no updating...
    4. No tween completion neither.
    (bumped onto this after pulling all hairs out of my head and finally starting to comment out line for line...)

    Would you be so kind to look into it?
    Many tnx in advance!

    Code (CSharp):
    1. [code=CSharp]//Code example;
    2.  
    3. DOTween.Init(true, true,LogBehaviour.Default);
    4.  
    5. //forget setting  value alphaEase does not result in any warning/error message...
    6. private DG.Tweening.Core.EaseFunction alphaEase;
    7.  
    8. public void startTweenFadeIn(int subTextIndex)
    9. {
    10. DOTween.To(() => currentColor, p => currentColor = p, endColor, tweenFadeTime)
    11.             .OnUpdate(callbackTweenFadeUpdate)
    12.             .SetEase(alphaEase)
    13.             .SetDelay(delayFadeOut * subTextIndex)
    14.             .SetSpeedBased(false)
    15.             .OnStart(callbackTweenFadeStart)
    16. .OnComplete(callbackTweenFadeComplete)
    17.             .SetId("GUItween" + indexNumber)
    18.             .SetTarget(this);
    19.  
    20.  
    21. }
    22.  
    23.     private void callbackTweenFadeStart()
    24.     {
    25.         Debug.Log("callbackTweenFadeStart() called");
    26.     }
    27.  
    28.     private void callbackTweenFadeUpdate()
    29.     {
    30.         Debug.Log("callbackTweenFadeUpdate() DOESNT get called..." );
    31.     }
    32.     private void callbackTweenFadeComplete()
    33.     {
    34.         Debug.Log("callbackTweenFadeComplete() DOESNT get called");
    35.  
    36.     }
    37.  


    Greetz,
    G
     
    Last edited: Oct 16, 2014
  9. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @gpvd Hi! You shouldn't store ease as EaseFunction, but as Ease:
    Code (csharp):
    1. private Ease alphaEase;
    EaseFunction is public only because that way users can create their own custom ease functions, but it's for really advanced usage (that's why I keep it in the Core namespace).
     
  10. gpvd

    gpvd

    Joined:
    Nov 2, 2013
    Posts:
    78
    Tnx for the advice;
    that solved it.

    Greetz
    G
     
  11. fionivar82

    fionivar82

    Joined:
    Oct 15, 2014
    Posts:
    4
    Outstanding. That is nearly the result that I'm trying to achieve. Is there any way to achieve this style of rotation (rotate around forward edge, not the coroutine) http://answers.unity3d.com/questions/8255/rolling-cubes-one-space-and-one-rotation-at-a-time.html - Is this possible, or is it outside the realm of DOTween's scope?
     
  12. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @fionivar82 If I understood that question correctly, you would simply want the cube to roll like it rolls now with LoopType.Incremental, but also pause 2 seconds between each 90° roll, right? If so, you *could* do that with a Sequence instead than a Tweener, but right now Incremental loops are not supported by Sequences. I'll see if I can fix that in the weekend.

    P.S. you could still achieve that by creating a Sequence and adding 10 relative-90°-rotation tweens (one for each roll) with an interval between each of them, but if I manage to make Incremental loops work there it'll be way easier.
     
  13. RemiR

    RemiR

    Joined:
    Dec 11, 2012
    Posts:
    21
    Hello,

    I would like to say thank you for your library. It is very powerfull and is a great job.

    However, I have a little question. Please tell me, if this code is it optimized ?

    Code (CSharp):
    1.     private void MoveToWaypoint()
    2.     {
    3.         var travelTime = Vector3.Distance(transform.position, Waypoints[_currentWaypoint].position) / Rate;
    4.         transform.DOMove(Waypoints[_currentWaypoint].position, travelTime)
    5.             .SetEase(Ease.Linear)
    6.             .OnComplete(() =>
    7.             {
    8.                 if ((++_currentWaypoint) + 1 == Waypoints.Length)
    9.                 {
    10.                     _currentWaypoint = 0;
    11.                 }
    12.                 transform.LookAt(Waypoints[_currentWaypoint].position);
    13.                 MoveToWaypoint();
    14.             });
    15.     }
    I used recursivity and i don't know if it's a good thing. It's probably better to use sequences no ? Can you give me an equivalent ?

    Thank you,

    Best regards.
     
    Last edited: Oct 16, 2014
  14. fionivar82

    fionivar82

    Joined:
    Oct 15, 2014
    Posts:
    4
    @Izitmee - Blast it all. I apologize, I was just aiming for the roll effect but I wasn't getting the behavior I expected (the cube would end sunken into a plane, facing the wrong way, etc). This was resolved with a 1unit cube instead of my custom 4^3 cube, so it's evident that I need to revise the code a little to get the right behavior.

    Thanks so much for the help. Now that I understand whats happening more I'm going to dive into the other tweens and learn those. Digging the package so far!
     
  15. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @RemiR Hiya! Actually, what you want to do could be done way more easily with the path shortcut (which is still in alpha but should have no problems with a "simple" animation like what you have). That is, if I'm right in understanding that you're trying to tween along a path with constant speed and infinite loops:
    Code (csharp):
    1. private void MoveToWaypoint()
    2. {
    3.    transform.DOPath(waypoints, totalTravelTime)
    4.       .SetLookAt(0.01f) // Orients to the path
    5.       .SetEase(Ease.Linear)
    6.       .SetLoops(-1);
    7. }
    8.  
    Just note that "waypoints" needs to be a Vector3 array instead than an array of transforms like you have it now.
    Cheers!

    @fionivar82 Glad you dig it!
     
  16. RemiR

    RemiR

    Joined:
    Dec 11, 2012
    Posts:
    21
    Super it's perfect now ! Thank you... I will continue to dev. with DOTween :)
     
  17. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Hey, maybe you have already decided on the pricing for the Pro? Will it come with the sources to have an ability to quickly patch something ourselves (if anything is broken and you need a quick build)?
     
  18. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Raimis I thought about $10. I actually was thinking of avoiding sources for the Pro, because being a "private-unless-you-buy" assembly I can't put it on Google Code like the rest of DOTween free. That said, Pro will offer additional features but is less complex than the Free version, in a way, so there should be no risks of something being terribly broken (and I'll run to fix bugs as usual).
     
  19. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    OMG, simple like this?!!!:eek:
     
  20. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @ZJP Miniaturization galore! :)

     
    YaVeTaL likes this.
  21. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    i need some help cant get it working. I want to play an tween only if no other tween is playing. Any suggestion ?
     
  22. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    meapps likes this.
  23. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    thank you
     
  24. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    got it working i love DOTween is pretty handy for simple animations.
     
  25. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Glad you like it :) And if you're into more complex animations, check out Sequences.
     
  26. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  27. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Just started using this plugin, really awesome. Clean code, clean doc, open sourced ...

    May I suggest a dl link with a non-dll version ? I know I can get it via the repo, but it's not really convenient.

    Thanks again for you work !
     
  28. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Glad you like it! Mhmm true: the fact that Google Code doesn't allow to download the repo as a zip is kind of a pain. I'll see if I can do something about it.
     
  29. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    How long until you would recommend it's use in production projects? This looks really interesting, I currently use Leantween due to speed, but this looks really nice.
     
  30. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Saxi Hi. DOTween is already being used in production projects (like Ghost of a Tale, SUPERHOT and my own Goscurry) and at the moment there are no known bugs, so I'd say it's safe to start using it. Only two things to pay attention to: the path plugin (DOPath) is still an early version, so if you need that wait for a couple weeks more. And the API is practically final but there still is a 5% chance that I change some minor things (nothing that would require complex changes to existing code though).
     
  31. Saxi

    Saxi

    Joined:
    Jun 28, 2013
    Posts:
    381
    Nice, have you done performance comparisons with LeanTween?
    Will you have a visual editor for complex paths?
     
  32. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Comparison with various engines is here (not updated to last version though). About the path editor there will be one in DOTween Pro (which will be an extra asset that can be bought, with the path editor and other additional tween features like DOSpiral), but for true complex paths I'm working on making DOTween work with Simple Waypoint System.
     
  33. Nemial

    Nemial

    Joined:
    Feb 25, 2014
    Posts:
    16
    So i know HOTween worked with NGUI way back when, but NGUI has had a few iterations since then and the anchoring system has changed, now the tween plays but it snaps back after playing...Perhaps some look into this? (i will also have a look and let you know if i find anything).

    EDIT:
    So looking into NGUI TweenPosition script i found NGUIMath.MoveRect(), which is what he uses to reposition the rect when the widget changes positions. so here is the crude way.

    Code (CSharp):
    1.  
    2. Vector3 start = topThing.localPosition;
    3. topThing.DOLocalMoveY(114,1).SetEase(Ease.OutBack).OnComplete(()=>{NGUIMath.MoveRect(topThing.GetComponent<UIRect>(), topThing.localPosition.x-start.x, topThing.localPosition.y-start.y);});
    4.  
    Or a little cleaner without having to cache the previous position.

    Code (CSharp):
    1.  
    2. topThing.DOLocalMoveY(114,1).SetEase(Ease.OutBack).OnComplete(()=>{TweenPosition.Begin(topThing.gameObject,0,new Vector3(0,114));});
    3.  
    Essentially on completing we are asking his in house tween script to do the movement at 0 duration. not pretty but it works
     
    Last edited: Oct 20, 2014
  34. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @Nemial If it snaps back it can only mean that NGUI doesn't allow that thing to be moved, and forces it to a given position at each Update/interval (which is overridden as long as DOTween is running, but when it stops NGUI takes control again). I don't use NGUI, but there must be a way to tell him to avoid snapping stuff.
     
  35. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Hm.. not sure, is it possible to set a callbacks in runtime? First call Fade(true, callback1); works fine, but second call Fade(false, callback2); is not restarting a tween.

    Code (CSharp):
    1. public class DarthFader : BaseSprite
    2. {
    3.     private Tween fadeIn, fadeOut;
    4.  
    5.     public override void Awake()
    6.     {
    7.         base.Awake ();
    8.  
    9.         fadeIn = DOTween.ToAlpha (() => sprite.color, x => sprite.color = x, 1, 0.5f).SetAutoKill().Pause();
    10.         fadeOut = DOTween.ToAlpha (() => sprite.color, x => sprite.color = x, 0, 0.5f).SetAutoKill();
    11.     }
    12.  
    13.     public void Fade(bool isFadeIn, DG.Tweening.Core.TweenCallback callback)
    14.     {
    15.         if (isFadeIn)
    16.             fadeIn.OnComplete(callback).Restart();
    17.         else
    18.             fadeOut.OnComplete(callback).Restart();
    19.     }
    20. }
     
    Last edited: Oct 20, 2014
  36. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Code (CSharp):
    1. public void Fade(bool isFadeIn, DG.Tweening.Core.TweenCallback callback)
    2.     {
    3.         if (isFadeIn)
    4.         {
    5.             DOTween.ToAlpha (() => sprite.color, x => sprite.color = x, 1, 0.5f).OnComplete(callback);
    6.             //fadeIn.OnComplete(callback).Restart();
    7.         }
    8.         else
    9.         {
    10.             DOTween.ToAlpha (() => sprite.color, x => sprite.color = x, 0, 0.5f).OnComplete(callback);
    11.             //fadeOut.OnComplete(callback).Restart();
    12.         }
    13.     }
    If not to cache them, it works fine.
     
  37. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @YaVeTaL The problem is that fadeOut is not playing when you call Fade. It plays the first time at creation (since it's not paused) and then is killed because you're setting AutoKill to TRUE (default). To set it to FALSE (and thus keep the tween for later use) you have to:
    Code (csharp):
    1. SetAutoKill(false)
     
  38. YaVeTaL

    YaVeTaL

    Joined:
    Sep 25, 2014
    Posts:
    29
    Aha, good to know. Though, that's a bit strange, because default(bool) = false.

    PS: yep, now it works fine.
     
  39. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Default optional parameters of a method and default values of a type are different things :p
     
  40. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Hi

    I noticed if I use the following...
    Code (CSharp):
    1. DOTween.Sequence()
    2.                 .Append(transform.DOMove(objectToMoveTo.transform.position,3,false))
    3.                 .Append(transform.DOLookAt(objectToLookAt.position,3)
    4.                             );
    The game object that is moving (the camera) doesn't appear to look at the requested game object (after the move), it looks somewhere near it! If I remove the DOMove command it works fine.

    Also this works fine too

    Code (CSharp):
    1.    
    2. IEnumeratorMoveIt () {
    3. transform.DOMove(objectToMoveTo.position,3,false);
    4. yield return new WaitForSeconds(3);
    5.  
    6. transform.DOLookAt(objectToLookAt.position,3);
    7.  }
    8.  
    Have I done something wrong? Thanks
     
    Last edited: Oct 21, 2014
  41. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @mattSydney Woah you're doing nothing wrong and that's a bug that shouldn't happen. I'm on it!
     
    Last edited: Oct 21, 2014
  42. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    mattSydney likes this.
  43. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    Trying to get working a blinking healthbar with Colours or Alpha. Any suggestions?
     
  44. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    To achieve a blink effect you can simply create an infinite loop tween with a LoopType.Yoyo.
     
    quangtqag and meapps like this.
  45. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    thx
     
  46. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    Could you add a shortcut that i can fade an UI text obj?
     
  47. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    @meapps: I use this code (on a Daikon Forge label, haven't switched to uGUI yet!). It starts flashing the time from the original color to red and keeps looping.
    Code (CSharp):
    1. Tween tweenTimeColour = DOTween.To
    2.   (()=> lbTime.Color, x=> lbTime.Color = x, Color.red, 1)
    3.   .SetEase(Ease.InOutSine)
    4.   .SetLoops(-1, LoopType.Yoyo);
    It would be cool if DOTween could simply tween *any* Color type directly, such as:
    Code (CSharp):
    1. lbTime.Color.DoTween(Color.red, 1f);
     
    Last edited: Oct 21, 2014
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    As Doug says :)

    I would love to be able to tween colors directly, but sadly a direct Color can't be referenced and thus changed over a period of time, so it's a no-go for a tween engine.
     
  49. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    P.S. to just fade a color, you use the generic ToAlpha instead than To.
     
  50. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    i just wish there would be a shortcut like image;)