Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

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

  1. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @wxxhrt

    No need for the OnRewind, just modify your SetLoops to something like this:

    Code (CSharp):
    1. SetLoops(-1, LoopType.Yoyo)
    Hope it helps!
     
    Izitmee likes this.
  2. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    139
    Hi @JakeTBear sorry I wasn't clear, when the object gets to the first waypoint (fully rewound) I want it to jump back to the last waypoint then move towards the first waypoint, rather than Yo-yoing.

    I've stripped everything extra out of my code to post here.

    Code (CSharp):
    1. public class PathGroupForum : MonoBehaviour
    2. {
    3.     public PathType pathType = PathType.CatmullRom;
    4.     public Transform prefab;
    5.     public float pathDuration;
    6.     public bool playBackwards;
    7.     private Vector3[] waypoints;
    8.     private Tween t;
    9.  
    10.     void Start()
    11.     {  
    12.         PathManager pathMan = this.gameObject.GetComponent<PathManager>();
    13.         waypoints = pathMan.GetPathPoints();
    14.  
    15.         Transform prefabOb;
    16.         prefabOb = Instantiate (prefab, waypoints [0], Quaternion.identity) as Transform;
    17.         prefabOb.transform.parent = this.transform;
    18.  
    19.         t = prefabOb.DOPath (waypoints, pathDuration, pathType)
    20.             .SetLookAt (0f)
    21.             .SetEase (Ease.Linear)
    22.             .SetLoops (-1, LoopType.Restart)
    23.             .SetAutoKill(false);
    24.  
    25.         t.fullPosition = pathDuration / 2f;
    26.  
    27.         if (playBackwards) {
    28.             t.PlayBackwards ();
    29.         }
    30.     }
    31. }
    When playBackwards is off the object gets to the last waypoint and jumps back to the start, when playBackwards is on it just waits at the first waypoint.
     
  3. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @wxxhrt Ah! alright, so if I understood correctly, this is a one way animation rather than Yoyoing. and since it is decided on start, you just want it to go from one point to another.

    I would suggest you revert the waypoints if it is meant to be played backwards.

    Code (CSharp):
    1.     public class PathGroupForum : MonoBehaviour
    2.     {
    3.         public PathType pathType = PathType.CatmullRom;
    4.         public Transform prefab;
    5.         public float pathDuration;
    6.         public bool playBackwards;
    7.         private Vector3[] waypoints;
    8.         private Tween t;
    9.    
    10.         void Start()
    11.         {
    12.             PathManager pathMan = this.gameObject.GetComponent<PathManager>();
    13.             waypoints = pathMan.GetPathPoints();
    14.    
    15.             Transform prefabOb;
    16.             if (playBackwards)
    17.             {
    18.                 Array.Reverse(waypoints);
    19.             }
    20.             prefabOb = Instantiate (prefab, waypoints [0], Quaternion.identity) as Transform;
    21.             prefabOb.transform.parent = this.transform;
    22.    
    23.             t = prefabOb.DOPath (waypoints, pathDuration, pathType)
    24.                 .SetLookAt (0f)
    25.                 .SetEase (Ease.Linear)
    26.                 .SetLoops (-1, LoopType.Restart)
    27.                 .SetAutoKill(false);
    28.    
    29.             t.fullPosition = pathDuration / 2f;
    30.    
    31.         }
    32.     }
    33.  
    Maybe this is not what you wanted exactly for other reasons, still, I would think that PlayBackwards would do it, odd if it is not the case, best of luck and I hope it helps!
     
  4. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    919
    Hi there,
    I purchased DotTweenPro few months ago but recently got a chance to actually use it.
    I really liked TMPro and UnityUI related extensions methods however i notice a big limitation which is lack of providing Easing Method, and Call Backs (On Success etc)

    For example
    rectTransform.DOScale(Vector3.one,0.5f);

    DOScale method doesnt take easing type, how can i provide that?

    Thanks
     
  5. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    139
    @JakeTBear Perfect! Thank you, that's so simple and does exactly what I'm after!

    EDIT: But PlayBackwards() not working with SetLoops(-1,LoopType.Yoyo) or SetLoops(-1,LoopType.Restart) might be a bug @Izitmee ?
     
  6. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    Hey John. You can add eases and callbacks to any Tween. Here's the documentation that explains how: http://dotween.demigiant.com/documentation.php#options
    So in your example:
    Code (CSharp):
    1. rectTransform.DOScale(Vector3.one,0.5f).SetEase(Ease.InOutQuint).OnComplete(MyCallback);
     
    Izitmee and jGate99 like this.
  7. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    919
    Wow, Thank you for reply with an example, really appreciated :)
     
  8. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    393
    Hi! Oh, thanks for for last time, tweening the gVars in Adventure Creator worked!

    Anyways, I have another question. I was wondering if there is a way to use DoTween as an alternative to a couroutine/invoke with a time delay. There's this script where I really need to use either of them but the class is not a MonoBehavior and creating and instantiating a prefab everytime I need to run the code just feels heavy handed and inelegant...

    Anyways, any advice will be greatly appreciated.
     
  9. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248
    Append an interval to a sequence.

    You should go read the help on Demigiant's site.
    Here's the part about Sequences.

    And here's a tip from the man, himself:
    "TIP: You can create Sequences made only of callbacks and use them as timers or stuff like that."

    And just `cause I'm an over-achiever, here's a method that will execute any Method after any interval utilizing DoTween
    Code (CSharp):
    1.  
    2. using DG.Tweening;
    3. using UnityEngine.Events;
    4.  
    5. public class NotAMonoBehavior
    6. {
    7.  
    8.     public void WaitForIt(float waitTime, UnityAction action = null)
    9.     {
    10.         DOTween.Sequence().AppendInterval(waitTime)
    11.              .OnComplete(() =>
    12.              {
    13.                  if (action != null)
    14.                  {
    15.                      action();
    16.                  }
    17.              });
    18.  
    19.     }
    20.  
    21.     private void SomeMethodSomewhere()
    22.     {
    23.         WaitForIt(1f, LoYetAnotherMethodIWantToExecute);
    24.     }
    25.  
    26.     private void LoYetAnotherMethodIWantToExecute()
    27.     {
    28.      // Do Fancy Stuff Here !
    29.     }
    30. }
    31.  

    You can simplify all that jazz by just calling a specific method from the Sequence.
    You can add numerous intervals and callbacks and logic inside the Sequence.
    Go nuts.
     
    Izitmee, Alverik and flashframe like this.
  10. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    393
    Hey, thanks! it worked beautiful. :D. Thanks to you, and thanks to Dotween for rocking so much!

    Really, I'm a one man team, and more of a designer/artist. I'm not a very good programmer, so all your help has been incredibly helpful!

    Anyways, again, thank you so much! :)
     
  11. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    @wxxhrt About PlayBackwards and infinite loops, you have to consider that a tween is like a movieclip, in a way. So if you play it backwards after 5 loops, it will play backwards 5 times. If instead you play it backwards before it even starts, nothing will happen. In short, infinite loops are infinite "forward" loops, and play backwards plays backwards from there until the beginning, considering all loops that elapsed.
    As a trick, you can use a Goto to go to some superfar time position (so that a big amount of loops has elapsed) and then PlayBackwards from there.

    @JakeTBear, @flashframe, @FuguFirecracker Many thanks ^_^
     
  12. tabor

    tabor

    Joined:
    Nov 29, 2011
    Posts:
    42
    Thanks, so easy!
     
    Alverik likes this.
  13. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    I'm using another tween engine and I'm thinking about porting all to DoTween if DoTween solves the issue I have with my other tween engine (DFTween).
    The problem I have is that I'm making a game that has a functionality to set the time scale to 10 or more, super fast. I did it so the player can skip whatever animation he wants (makes sense with my game idea).

    The problem is that the tween engine I'm using starts when the next update is called, does not move the first "step" of the tween instantly after calling it. In a normal time scale this is not too much time, but when the time scale is 10 or more, this is a lot of inactivity time and breaks everything.
    I noticed that DFTween uses Update internally instead of FixedUpdate. Update does not gets affected by the time scale so that is the true issue I think.. So if DoTween uses FixedUpdate, that should fix my problem.

    Is DoTween using FixedUpdate internally or fixes this issue in a different way?
     
  14. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hey @fermmmm, long time no see ;)

    DOTween can use both Update, LateUpdate, FixedUpdate, plus a combined timeScale-independent update system, depending on the setting you choose by default (or the one you apply to a specific tween via SetUpdate).

    That said, I'm not sure what's the problem with timeScale and DFTween's behaviour. DOTween too starts (if with "starts" you mean "changes the target's value for the first time"—unless it's a FROM tween) in the next frame you call it, which is the correct behaviour for any tween engine. If the timeScale is faster, for example 10x, it just means that the first time said target's value is changed (which will happen when the tween starts) it will change 10x more than usual, as with the rest of the frames.

    I use to set the timeScale up to 30x when debugging my games (if they're action-based), and let it run for a while with debug AI, and never encountered any tween issue. But maybe I misunderstood what your issue is?
     
  15. inxidious

    inxidious

    Joined:
    Nov 8, 2013
    Posts:
    16
    Hi, really great tween engine, running pretty smoothly so far.

    i'm just wondering if i can use PauseAll() with idsOrTargetsToExclude parameter just like in KillAll() ?
    Or i need to set the ids for all the tweens that can be paused? it's really inconvenient though because most of my tweens should be paused when the game pauses. :)
     
  16. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    I used to have my game tweens with DoTween a long time ago and my problem still happened, so I thought that the tween engine was not related to my problem. But now I ported back the tweens to DoTween to try to solve this problem and I solved it!!.

    I was testing my game with timeScale set at more than 10, my game contains a lot of tweens and AI characters that scapes from explotions, the Ai was sometimes scaping the explotions too late or the explotions were triggered too soon (both things are related with tweens), so the AI was getting killed more when the time scale was more then 10, when I set the update mode to FixedUpdate for all the tweens the problem was gone.
    I had this problem since like 6 months ago and I was thinking all the time what could be the problem. Thinking that my AI code was wrong. Finally I could solve it. Now I can test my game much better using timeScale.
    This could happen again to other people, I wonder why FixedUpdate is not the default update mode for the tweens, since that gives proper support for timeScale, is beacuse of performance?

    Maybe you should add some warning in the documentation explaining that if you are going to change the time scale you should use your tweens in the Fixed update mode specially when the tweens interacts with the logic of the game otherwise the timings of the game will be broken and that can brake the entire game.

    Or you can even make an automatic update mode that switches to FixedUpdate when timeScale is more than 1.0
     
    Last edited: Jul 23, 2016
  17. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    @inxidious Sorry but no idsOrTargetsToExclude parameter except than in KillAll. But you could use a different logic. For example, when I want tweens to be paused when the game pauses, while keeping a few working, I just set those few that should work as TimeScaleIndependent (SetUpdate(true)), so when I set the game's timeScale to 0 every tween will stop working except those independent ones.

    @fermmmm That is very interesting and I actually didn't know it. That would mean that Unity reports a wrong Time.deltaTime inside Update the first frame that timeScale changes. I'll investigate that.
    P.S. If you haven't, grab the latest DOTween from the website, not the Asset Store (the Asset Store version is a little behind, should update next week).
     
  18. inxidious

    inxidious

    Joined:
    Nov 8, 2013
    Posts:
    16
    @Izitmee ahh.. of course that's a better approach, i never thought of that. Thanks :D
     
  19. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    I'm not sure about the problem at the start of the tween, that was just a theory. I think the problem in my game was caused by the tween in Update mode instead of FixedUpdate, Update does not work with time scale.
     
    Last edited: Jul 24, 2016
  20. pioj

    pioj

    Joined:
    Nov 5, 2012
    Posts:
    15
    I have this Sequence where I do some tweens to a List of elements inside a For... Loop. One of the steps involves a SetTrigger(animstate) to a frame-based Animation. This needs to happen inbetween two Tweens (insert, blablabla..)

    The problem is, using Callbacks I still can't get the anim to playback at the right timing, as it messes the whole thing. The Animator simply goes it's own way.

    So , is there any way/ideas to mix Meccanim anims with DOTween? The issue is related about how to structure my Function so I can do everything from a loop and still get the timings right.

    Thx a lot.
     
  21. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    252
    Hi,

    It seems I can't compile in Android using the new Unity v5.4.0 (using last Dottween Pro v0.9.470 on Windows 10).
    Error:
    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    Any help???

    Extended console msg:
     
  22. hattori

    hattori

    Joined:
    Oct 18, 2014
    Posts:
    21
    I'm getting the exactly same errors with jocyf using Unity 5.4.0f3 and DOTween 1.1.310.
    When I play in Unity Editor, I find no problems but when I build Android apk, it throws those errors in console.
     
  23. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    66
    Hi!
    I'm trying to understand how to get my grid-based 1st person movement going (think Grimrock, eye of the beholder) but having problem having it work correctly.

    I have a player object with the camera in it and I move and rotate this object around. I used iTween and it worked, to the logic should be fine - what iTween had though was I could set space = self, which I could rotate the object around and move forward along it's z.axis instead of the world z axis.

    I made it work by having a parent of the player object, rotating the parent, and localMove on the child. This makes it move along it's own z.axis - problem is ofcourse when I rotate the parent(which isn't moving along with the child player object) as it's not centered where the player stands.

    How would I go about to do this in theory? Am I correct in my understanding that to be able to move along it's own axis it needs to move in a parent? Is there anything equivalent to Space.Self on the DOmove?

    (I'm using playmaker, but the actions themselves should be fine, I think I just don't understand how DOTween should handle cases like this)
     
  24. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    There's an option in DORotate and DOLocalRotate to set the RotateMode to "LocalAxisAdd"

    Code (CSharp):
    1. DOLocalRotate(Vector3 to, float duration, RotateMode mode)
     
  25. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    66
    Thanks for the help! But I'm not sure if that would help.
    My Player object does rotate the axis correctly when checking the editor at runtime. But my problem is that the DOMove doesn't move along the objects axis, it always seems to move along the world axis (unless I put it in a parent and rotate the parent, as mentioned above)
     
  26. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    @DanielThomas Ah I see, I misunderstood, sorry. You could do what you want with a generic tween, moving the position yourself. But there maybe a built in way to do this, so I'll defer to @Izitmee
     
  27. PixelizedPlayer

    PixelizedPlayer

    Joined:
    Feb 27, 2013
    Posts:
    409
    So i am trying to change the alpha of a image component for my UI but it does not seem to allow it. This is what i tried:

    I get this error:

    How can i fix this?
     
  28. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,919
    dt pro in 5.4 spits out a vague naggy warning each time the game runs, maybe it's related? I'm sure @Izitmee will throw up a patch when he sees it.
     
  29. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248
    Your error has nothing to do with DoTween.
    You cannot modify image.color.a because it is not a variable.
    You have to create a Color variable
    Code (CSharp):
    1. private Image _image;
    2.  
    3. _image.color.a = 128; // DOES NOT WORK
    4.  
    5. // You need to to create a new color
    6.  
    7. Color32 iColor = _image.color; // copy original Image color
    8.         iColor.a = 128; // modify the alpha only
    9.         _image.color = iColor;  // assign to image
    10.  
    11. // ### OR ###
    12. // inline it
    13.  
    14. _image.color = new Color32((byte)_image.color.r, (byte)_image.color.g,(byte) _image.color.b, yourAlphaHere);
    15.  
    16. // ## OR ##
    17. // use DoFade
    18.  
    19.  
     
  30. KhashayarJan

    KhashayarJan

    Joined:
    Jul 25, 2016
    Posts:
    8
    Hi

    I have a 2D game and I'm using the visual editor of DOTween Pro. I want to throw a grenade and I can create a path to do it but it would be static so if I create another grenade from different position, it would then just go back to the place of the first grenade (prefab). I am placing it at my desired place and if I disable DOTween, it stays at where I want it to start but after enabling DOTween it goes back and then moves along the path.

    Also is it possible to have is ease in mid-air by some how choosing few waypoints to slow speed and then again increasing it. Like when tossing something in real life, that in most height, velocity of y is 0.
     
  31. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @KhashayarJan Hey, I have done this. I am not aware if a better way of doing this has been created but what I used to do is create the prefab I want to move along the path, then create the actual path (from another prefab), and attach my game object (in this case, your grenade) to the path object. This will make it so it moves along its parent while being at the original position you instantiated it.

    Hope this helps!
     
    KhashayarJan likes this.
  32. KhashayarJan

    KhashayarJan

    Joined:
    Jul 25, 2016
    Posts:
    8
    @JakeTBear
    I'm not sure I understand it completely. Can you explain more?
    Thanks!
     
  33. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Sure, lets say you create a path in the editor, lets call this PathGameObject, once you finish the desired path in PathGameObject, you go ahead and create a prefab from it. So your PathGameObject will turn blue indicating it is a prefab.

    The contents of PathGameObject should be its Path component and the transform, maybe a manager if you plan to pool it (so it reset if reused).

    Then lets assume your Grenade that wants to use this path has a script that does the following:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.  
    4. public class PathGrenade : MonoBehaviour
    5. {
    6.     public GameObject _PathGameObject; //the prefab that contains the path
    7.     void OnEnable()
    8.     {
    9.         //here the Grenade has the desired start position, so we just need
    10.         //to create the path from the prefab and attach
    11.         transform.parent = GameObject.Instantiate(_PathGameObject).transform;
    12.         //If the Path is set to run on start, the granade will move along
    13.         //regardless of where it is relative to the path, and it will do the
    14.         //same motion as the parent path
    15.     }
    16. }
    That in a nutshell, I hope it helps!
     
  34. Schizoid2k

    Schizoid2k

    Joined:
    May 6, 2015
    Posts:
    34
    Does anyone have some experience using DOTween with TextMesh Pro? I am having a bit of difficulty.

    I recently purchased TMP and added it to my project. I then followed the instructions on the DOTween site and re-imported DOTween and ran the setup.

    I do not see any of the TMP shortcuts... I particularly would like to use DOFontSize.
    I do see ShortcutExtensionsTextMeshPro.DOFontSize, but I am having difficulty with that.

    Would someone be able to provide a little code? This is what a tried (and failed).

    Code (CSharp):
    1. using TMPro;
    2. using DG.Tweening;
    3.  
    4. public TMP_Text myText;
    5. private Tween tween;
    6.  
    7. void PerformTween() {
    8.     // DoFontSize not available as a choice in list
    9.     tween = myText.DoFontSize(54, 1f);  
    10.  
    11.  
    12.     // error CS1503: Argument `#1' cannot convert `TMPro.TMP_Text' expression to type `TMPro.TextMeshPro'
    13.  
    14.     tween = ShortcutExtensionsTextMeshPro.DoFontSize(myText, 54, 1f);
    15.  
    16.     // casting does not help
    17.     // InvalidCastException: Cannot cast from source type to destination type.
    18.     tween = ShortcutExtensionsTextMeshPro.DoFontSize((TextMeshPro)myText, 54, 1f);
    19. }
     
    KhashayarJan likes this.
  35. Schizoid2k

    Schizoid2k

    Joined:
    May 6, 2015
    Posts:
    34
    D'oh, figured it out...

    Code (CSharp):
    1.     private Tween tween;
    2.  
    3.     public TextMeshProUGUI myText;
    4.  
    5.     // Tween the font size of selected item
    6.     private void Tween() {
    7.         tween = myText.DOFontSize(52, 1f);
    8.     }
     
  36. sirio21

    sirio21

    Joined:
    Mar 11, 2013
    Posts:
    114
    Hi! im new in Dotween. I have a stick rope. How can a i set the pivot at top of the rope (local 0,0) in order to do a rotate from this pivot?
    Thanks!!!!
     
  37. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @sirio21
    Hey, you can achieve this a couple of ways, the straight forward way would be to animate your own "RotateAround" using DoTweens lambas. This could be a little complicated, so the recommend way would be by using a parent object.

    So you first create an empty GameObject, add the rope element you want to rotate as a child of the empty gameobject and then finally rotate the parent.

    Hope this helps.
     
  38. Schizoid2k

    Schizoid2k

    Joined:
    May 6, 2015
    Posts:
    34
    I'm still having a problem using DoTween with TMP UI. I have some text I want to animate. I created a font asset, created and applied a material preset to the text. The preset has a green outline.

    When I try to animate the ouline via DOOutlineColor, it does not work. Looking at the Inspector, it seems that the text no longer has my material preset assigned.. it reverts back to the standard, white font asset, so the animation does not occur. Interestingly, the text still is displayed on the screen with the green outline.

    While in run mode, if I choose the material preset of the text that was changed back to the plain font asset, and select my material preset from the drop down, the animation works.

    Has anyone experienced that? Am I doing something wrong?

    thanks
     
  39. Schizoid2k

    Schizoid2k

    Joined:
    May 6, 2015
    Posts:
    34
    bump...

    Anyone experience this issue with DOTween / TMP?

    thanks
     
  40. Green-Sauce-Games

    Green-Sauce-Games

    Joined:
    Mar 27, 2014
    Posts:
    69
    Is it possible to create a DoMove Tween where the destination is a variable point that can change during the Tween?
     
  41. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Hi there. I've just started using DOTween and already encountered a problem.
    I'm trying to use the following simple sequence:
    Code (CSharp):
    1. Sequence sequence = DOTween.Sequence().SetLoops(-1);
    2. sequence.Append(transform.DOLocalRotate( leftVec, halfDuration).SetEase(easing))
    3.         .Append(transform.DOLocalRotate(rightVec, halfDuration).SetEase(easing));
    But it seems that when the sequence starts playing from the beginning the transform somehow appears to be reset.

    Note: the gif is seemless. That's the issue I'm talking about.

    I found the workaround, but it's not so compact as the initial code. Any ideas?
     

    Attached Files:

  42. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248
    Code (CSharp):
    1.  Sequence sequence = DOTween.Sequence().SetLoops(-1, LoopType.Yoyo);
     
  43. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248
    Hey hey
    Show some code where you attempt this endeavor, and I shall endeavor to help.
    My guess is
    Code (CSharp):
    1. .OnUpdate()
    would be useful ;)
     
  44. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Thanks, but nope.
    This will make the animation play back and forth, but the problem will persist.
     
  45. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248

    Well then try this slice of fried gold !
    Code (CSharp):
    1. using DG.Tweening;
    2. using UnityEngine;
    3.  
    4. public class Sway: MonoBehaviour
    5. {
    6.     private float _halfway = 3;
    7.  
    8.     private Vector3 _swayVector = new Vector3(0, 0, 20);
    9.     private Transform _transform;
    10.  
    11.  
    12.     protected void Start()
    13.     {
    14.         _transform = GetComponent<Transform>();
    15.         Sway(_swayVector);
    16.     }
    17.  
    18.     private void Sway(Vector3 v)
    19.     {
    20.         _transform.DOLocalRotate(v, _halfway).OnComplete(() => { Sway(-v); });
    21.     }
    22. }
     
  46. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Thanks again. Yep, that's the workaround I mentioned in my first message here.
    But I'd like to know why DOTween resets the transform. Is it a bug or is it intentional behaviour and I do something wrong?
     
  47. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    399
    Tweens get cached when you make them. When you create your Left & Right Tweens, they both hold the initial rotation of the tree as their starting point. So when the second tween plays, it is jumping to its cached starting position, which happens to be the middle in this case.

    So you could start the tree rotated to the left, and then Tween it to the right and use a yoyo loop on that. You can also use Goto to start the animation halfway, so the tree starts in the center. Something like this (untested).

    Code (CSharp):
    1. transform.localEulerAngles = leftVec;
    2.  
    3. Tween tween = transform.DOLocalRotate( rightVec, fullDuration).SetEase(easing).SetLoops(-1, LoopType.Yoyo);
    4.  
    5. tween.Goto(halfDuration, true);
    6.  
    7.  
     
    Last edited: Aug 12, 2016
  48. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    248
    Uh...
    It's not a 'workaround' if it's how it's actually done ;) LOL
     
  49. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    140
    Oh... Thanks for clarification. I had the feeling that I'm missing something fundamental and it appeared to be the caching.

    Wellp... I'm switching from Cocos2d-x to Unity and that's how I did that in C2dx:
    Code (csharp):
    1. Action* swing = RepeatForever::create(
    2.     Sequence::createWithTwoActions(
    3.       EaseQuadraticActionInOut::create(RotateTo::create(swing_duration, tree_angle + swing_angle)),
    4.       EaseQuadraticActionInOut::create(RotateTo::create(swing_duration, tree_angle - swing_angle))));
    5. tree_sprite->runAction(swing);
    I believe that this behaviour is more intuitive and easy to predict.
     
  50. PixelizedPlayer

    PixelizedPlayer

    Joined:
    Feb 27, 2013
    Posts:
    409
    Hello

    I have a simple tween like this:

    Code (CSharp):
    1. DOTween.To(() => myObj.localPosition, x => myObj.localPosition = x, target, 12f).SetEase(Ease.InOutQuad);
    And i want to get an ID of some kind for it to assign to a public variable in my class so that i can then cancel / abort it. Was wondering how i can do this?