Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DOTween (HOTween v2), a Unity tween engine

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

  1. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Did you setup DoTween?
    From the Unity Menu:
    Tools>Demigiant>DoTween Utility Panel

    Also, DOMoveX does not accept a Vector3.

    It requires a float.
    Which will be applied to X.
    There will be movement
     
  2. myke808

    myke808

    Joined:
    Mar 16, 2018
    Posts:
    1
    Hi! Newbie here on DOTween. So um, does it work on instantiated objects? Mine does n't seem to move after I applied DOMove.

    Thanks!
     
  3. jcuriel_glu

    jcuriel_glu

    Joined:
    May 26, 2017
    Posts:
    16
    Where exactly are you adding the mAnim.SetAutoKill(false)? I'm unable to play backwards at all and I've created a similar set up to what you've done here.
     
  4. jcuriel_glu

    jcuriel_glu

    Joined:
    May 26, 2017
    Posts:
    16
    Damn it, of course I'd find the answer through trial and error. I was able to get this working by adding mAnim.SetAutoKill(false) to the end of the sequence setup, but is this really the right answer?
     
  5. pep_dj

    pep_dj

    Joined:
    Nov 7, 2014
    Posts:
    179
    I bought PRO version, and I have a basic question:

    I do
    Code (CSharp):
    1. transform.DOMove(new Vector2(100, 100), 1);
    and after 1 second, the final position is not (100, 100), it's (99.8926, 101.2788). Is this the correct behavior? I didn't expect that...
     
  6. Rodolinc

    Rodolinc

    Joined:
    Sep 23, 2013
    Posts:
    63
    Hi @Izitmee why DOMove takes no difference when using very small numbers? I'm trying to move an object 0.1 but from 0.5 to 0.1 there´s no noticeable difference, and from 0.5 to 1 is a huge difference.I guess it has somethign to do with float point calculations or maybe there is an ease curve affecting the move?
     
  7. matrix211v1

    matrix211v1

    Joined:
    Jan 20, 2009
    Posts:
    193
    I would like to know what GameObject has finished their Tween when calling an OnComplete. When the function of the OnComplete finished, I want to check that GameObject, see if it's in a specific position, and if not, redo the same tween again.

    Something like:

    Code (CSharp):
    1.             symbol.GetComponent<RectTransform>()
    2.                 .DOLocalMoveY(symbol.GetComponent<RectTransform>().localPosition.y + (-_moveDistance), 1.0f, false)
    3.                 .SetEase(Ease.Linear).OnComplete(FinishedTween(symbol));
    Then the FinishedTween should be something like this:

    Code (CSharp):
    1.  
    2.     private void FinishedTween(GameObject symbol)
    3.     {
    4.         Debug.Log("Finished" + symbol.gameObject.name);
    5.         if (symbol.GetComponent<RectTransform>().localPosition.y < 1000)
    6.         {
    7.             symbol.GetComponent<RectTransform>()
    8.                 .DOLocalMoveY(symbol.GetComponent<RectTransform>().localPosition.y + (-_moveDistance), 1.0f, false)
    9.                 .SetEase(Ease.Linear).OnComplete(FinishedTween(symbol));
    10.         }
    11.     }
    12.    
    Any suggestions?

    Thanks!
     
    Last edited: Aug 10, 2018
  8. Snookz

    Snookz

    Joined:
    Jul 23, 2017
    Posts:
    2
    Hello friends,

    I'm trying something I think is very simple, but I don't quite get it. I want to move my camera while tweening it looking at a specific point. On the starting point, the camera does not look on that point, so just calling a LookAt(target) in DOMove.OnUpdate() doesn't work because on the first OnUpdate() the cameras rotation changes instantly, looking really odd.

    So here is what I came up with:

    Code (CSharp):
    1.  moveTween = transform.DOMove(targetPos, 2, false).SetEase(ease).OnUpdate(DoLookAt);
    2.  
    3.     public void DoLookAt()
    4.     {
    5.         transform.DOLookAt(defaultFocus, (1 - moveTween.ElapsedPercentage())*2).ChangeStartValue(transform.rotation);
    6.     }
    The (1 - moveTween.ElapsedPercentage())*2) makes sure the rotation stops when the movement stops, because 1 - elapsed is eventually 0.

    I have three problems with my "solution":
    1. The start still looks a bit "jumpy/odd".
    2. DoLookAt() starts a new tween every call, which is not really what I want and maybe can lead to problematic behaviour.
    3. There must be a more elegant/sophisticated way to do this, which I can't see.

    I hope you guys can help me...
    Thank you!

    Edit:

    I also tried playing around with ChangeStartValue() and ChangeEndValue(), but I don't really know what those values are when doing DoLookAt(). Using the positions give me weird results.
     
    Last edited: Aug 14, 2018
  9. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Is there any information on the new DOTTween modules?
     
  10. Snookz

    Snookz

    Joined:
    Jul 23, 2017
    Posts:
    2
    Apparently I found a solution, leaving only two tweens open and synchronizing the duration of the rotation and the movement:

    Code (CSharp):
    1. Tweener lookTween = transform.DOLookAt(defaultFocus, 2).SetEase(Ease.OutQuart);
    2. Tweener moveTween = transform.DOMove(targetPos, 2, false).SetEase(ease);
    3. moveTween.OnUpdate(() => lookTween.ChangeValues(transform.rotation.eulerAngles, defaultFocus, (1 - moveTween.ElapsedPercentage()* 2)));
     
  11. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Hi! I bought DoTween Pro a couple of weeks ago and finally now trying to use it. I've searched the official website and just couldn't find a good example on whether my requirements below is possible. Hope someone can shed some light on this:

    Is there a way for a single GameObject to have more than one Path and be controlled by a script in choosing which path it can take at a given moment in time? For example, it has a path for going to the basement then another path to go to the kitchen, etc. But the GameObject only moves to the proper location when the Player makes the correct action like pressing a Key.

    Also, is there a sample script available on how to activate a path movement if it's not through a Button? For example, it is time-based / event-based. The official video only shows how by using a Button.
     
  12. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    @Izitmee I have updated to the new version and I have a problem.

    Before you had all your code compiled in dlls. Now you have modules in simple *.cs files where you change a true/false depending if we have enabled or disabled the module.

    My problem is that I use *.asmdef files and now I have to create an *.asmdef file for your "Modules" folder scripts because if I don't do that I can't reference them from my code.

    Could you create a *.asmdef file for the modules folder? Thanks.

    It should not be a problem for older Unity versions because they would not process that file as it doesn't know what it is.
     
  13. vanlecs09

    vanlecs09

    Joined:
    Dec 26, 2014
    Posts:
    1
    how can i make a linear rotation with dotween?
     
  14. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    27
    Hello everyone,

    I'm getting errors in the DOTweenModuleUnityVersion script that are preventing me from building the project. Errors seem to be related to some deprecated fields/methods that relate to color for 'Material' and 'DG.Tweening' not containing a member 'Append'.

    I thought it could be related to my Unity version by i'm currently running Version 2017.1.3p3 Personal and the
    public static class DOTweenModuleUnityVersion
    uses
     #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1_OR_NEWER
    #region Unity 4.3 or Newer


    So i'm not too sure what to do here and i really do hope to get a solution especially because i just bought the Pro version :)

    EDIT: Had a global enum that was conflicting with "Material". I feel silly for naming something "Material"
     

    Attached Files:

    Last edited: Aug 17, 2018
  15. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    @Izitmee doesn't look on this forum very often.
    Try contacting him on Twitter: @demigiant
     
    Tycellent likes this.
  16. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    27
    Crap i had a global enum that was conflicting with "Material".
     
  17. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    "- NEW: DOTweenAnimations can now be previewed directly in edit mode"

    :D
     
  18. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    Hi all,

    I'm using DOTweenPro and I've got a major issue with DOPath that I can't quite seem to resolve.

    I'm trying to make an object travel along a circular loop path, which can be 'reversed' at any stage and continue the loop in the other direction, using the Flip(); command. The eventual goal here is to make a object fly around a general path until specifically told to do otherwise, where it will go off the path to a point, then fly back again and resume.

    Rather than using the loop function, I have it loop once, then restart when it hits either the end or start waypoints depending on direction. I am doing as when it is reversed, it won't loop otherwise (as it's considered the 'start' of the tween).

    My problem is this however - regardless of direction (or even if I use the loop settings as intended), when it goes from final waypoint to the first again, it will fire the OnWaypointChange of all the waypoints in reverse... It seems like a bug - but I presume this has something to do with the backend calculations 'travelling' along all the waypoints in reverse to get back to the start again.

    This of course causes havoc as I am monitoring those waypoints with specific actions and it will trigger all of them rather than just looping back to the first waypoint.

    Is there something obvious i'm missing? Is there a better approach to this then using DOPath?

    Much appreciated.
     
  19. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I like DoTween for its flexibility but for using multiple paths and switching over them, I can't seem to get it to work. I have DoTween Pro but the Visual Path Editor is quite limited. Can someone share a simple working example code on how to use multiple paths and how to switch over them?

    I was considering on getting Simple Waypoint System (SWS) (US$ 15) too which also uses DoTween but I'm not sure if it's worth it if I already have DoTween Pro because I find information lacking on what I need. There is no clear explanation or even a video on how multiple paths and switching over them works... which I guess would be the main reason why most people will get that asset. Also, the single video available looks like it works similarly to the Visual Path Editor that comes with DoTween Pro. I've also found Easy Waypoints - Path System (EWPS) (US$ 5) which lists down some functionalities I might need and does not use DoTween. So I'm now comparing the two (SWS vs. EWPS) and which would be suitable if I already have DoTween Pro. I guess in my setup, the advantage of using SWS is I can use the same tweening engine and save some space and avoid duplicate functionalities. If I use EWPS, I'm assuming it might be easier to use and must already have more robust "visual path editor" features than SWS (still to be confirmed but looks like it based on their video). Has anybody tried any of these tools and can share some feedback?
     
    Last edited: Aug 30, 2018
  20. ExLight0902

    ExLight0902

    Joined:
    Apr 26, 2015
    Posts:
    3
    Anyone help me how to use DOVirtual.EasedValue method ? i have read document but i till understand completely to use it in game
     
  21. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    You use it like you would use Mathf.Lerp. You give it a start value, an end value, and progress percentage (0-1), and it will return an eased value.
     
  22. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    I've managed to make a workaround for this. Thought I'd mention it in-case any one else has the same issue and sees this post.

    In short - I have one loop. If it reaches the end of the loop in the forward direction, I ignore waypoint events and restart the loop. If it reaches the start of the loop (in reverse direction) I ignore events and place it back in the start position.

    Here's a breakdown of how I've done it:
    I use a boolean to indicate whether we're in forward or reverse.
    I have an additional boolean to specify whether waypoint events should be ignored - IgnoreWaypoints.
    I set my loops to 1 for DOPath (not -1). (This allows us to control the loop beginning and ends).
    I have two callbacks on the path: OnComplete() and OnWaypointChange().

    OnComplete is triggered when we reach the end of the loop in the forward direction. This will set IgnoreWaypoints to true, call path.Restart(); then set it false again.

    OnWaypointChange will be triggered every waypoint. However, I only have it run any code if my 'IgnoreWaypoints' bool is false.
    If it registers the current waypointIndex to be 0, it will disable events, call path.GotoWaypoint(waypoints.Length +1, true) . This will jump it to the 'end' of the loop and continue to play backwards.

    Seems quite a bit of work for something simple - but I think I understand why it's necessary. From what I can tell, I think DOPath only loops in one direction and continually builds its path after each loop, so if you reverse it, it will stop at the starting position after how many loops have already traversed.

    Another thing to note which might confuse people - (it did for me) - DoPath uses it's own waypoint array that has more waypoints than are supplied in the Waypoint array where you copy to clipboard (it has an additional index for the 'start' position of your object) - this can be really confusing as the 'waypointIndex' parameter of OnWaypointChange may not match up.

    I don't know if there's a way to get an array of Waypoints directly from the path - you can do it with path.PathGetDrawPoints() if you just want a linear path, but for Catmul Rom it will do every bit of the curve. If anyone knows, let me know!
     
    RendCycle likes this.
  23. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I was hoping that sort of thing can be handled more easily by using another tool like Simple Waypoint System or Easy Waypoints - Path System. But it's difficult to say with lack of upfront examples. Thanks for sharing your solution on what to expect if just using DoTween! :)
     
  24. Eldirfar

    Eldirfar

    Joined:
    Feb 9, 2014
    Posts:
    65
    How to disable automatic DOTween Utility Panel at first compilation of project? I build my project via Jenkins and it stucks when some popup showns. Does this configurations shouldn't be shared when project is downloaded from repository?
     
    Last edited: Sep 6, 2018
  25. KrzysztofX10

    KrzysztofX10

    Joined:
    Aug 12, 2017
    Posts:
    8
    Hi everyone,
    I just encountered a small problem in DoTween Pro v1.0.065. In the DoTween Rotate animation inspector it is impossible to toggle between rotating to "value" and rotating to "target", despite the fact that it is perfectly possible when making the animation as a Playmaker action. The button to toggle is present in the inspector for DoTween Move animation, but not for DoTween rotate animation.
    Does this happen to anyone else? If so, have you found any workarounds to rotate to target without Playmaker?
     
  26. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Hi, i'm trying to rotate an object by 180 degrees. Any idea how i can control the direction it will rotate in?
     
  27. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    Hrm, rather than setting a specific rotation, you can rotate it to its current rotation plus or minus 180 depending on the direction you wish it to turn?
     
  28. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    I've managed to write a function into my code that merges between two paths.

    For a short description:
    Essentially I have two gameobjects with paths in the editor. The first has my animated object as its child. When the path finishes, I perform a DOTween to take the object to the first 'drawpath' of the second path, swap its parent to the new path, then play. To get the rotation to work right, i point the object towards the second waypoint of the second path. When it swaps parents, I 'force' it to look at the direction fast.

    There's a very short noticable 'blip' between the paths when I swap the parents and the rotations are slightly off. If I figure out a way to smooth that out I'll update it.

    Here's a quick version in code of what happens (may be some syntax errors).

    Code (CSharp):
    1.  
    2. Start() {
    3.             firstPath = firstPathGameObject.GetComponent<DOTweenPath>();
    4.             secondPath = secondPathGameObject.GetComponent<DOTweenPath>();
    5.             firstPath.OnComplete(JoinPaths);
    6.             firstPath.Play();      
    7.             secondPath.Pause();
    8.         }
    9.  
    10.         private void JoinPaths() {
    11.             animatedObject.transform.DOLookAt(secondPath.GetDrawPoints()[1], 3F, AxisConstraint.Y).SetEase(Ease.Linear);
    12.             animatedObject.transform.DOMove(secondPathGameObject.transform.position, 3F).SetEase(Ease.Linear).OnComplete(StartSecondPath);
    13.         }
    14.  
    15.         private void StartSecondPath() {
    16.             animatedObject.transform.SetParent(secondPathGameObject.transform);
    17.             animatedObject.transform.DOLookAt(secondPath.GetDrawPoints()[1], 0.01F, AxisConstraint.Y).SetEase(Ease.Linear);
    18.             secondPath.Play();
    19.         }
    20.  
    21.  
     
  29. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Finally an answer! Thanks for the reply and I appreciate it! :) However, I will have to check this out later on because I was able to already get another Waypoint system working...
     
  30. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    No problem! I'd be keen to hear about the other waypoint systems and how you go with them. I'm new to this and as much as I love DOTween i'm sure there might be better suited solutions to the specific sorts of things I'm doing out there :).
     
  31. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I'm not yet sure if the Waypoint System I'm using is more advanced than DoTween Pro with regards to extending it by scripting. But for me, it is easier and quicker to use and has more features when compared to the Visual Path Editor. I was initially planning on learning how to extend DoTween through scripting but just couldn't find more detailed working examples using multiple paths or controlling animation/movement per waypoint. I read the 3 pages of the other Waypoint System (mentioned in previous post. Not using DoTween) and I was able to use it immediately after a couple of minutes even if it has a tiny bit of "manual" approach. :D I plan to still use DoTween Pro, but maybe for other things.
     
    Last edited: Sep 12, 2018
  32. Turkm

    Turkm

    Joined:
    Feb 1, 2015
    Posts:
    7
    Hi,
    why i got this error, the first tween in sequence worked fine but the second got error, why???
    Untitled-1.png
     
  33. Turkm

    Turkm

    Joined:
    Feb 1, 2015
    Posts:
    7
    even with the shortcut way still cant find any solution!!! Untitled-1.png
     
  34. Turkm

    Turkm

    Joined:
    Feb 1, 2015
    Posts:
    7
    So if your duration is a fraction number
    you have to add ( f ) to explicitly announce its a float number
    Untitled-1.png
     
  35. evoros

    evoros

    Joined:
    Dec 2, 2015
    Posts:
    3
    Hi all! I tried adding my own extension method for float hoping to reduce the generic DOTween.To() syntax. The goal would be so that instead of writing:

       pointsTween = DOTween.To(() => points, x => points = x, 100, duration);


    I could just write:

       pointsTween = points.DOFloat(100, duration);


    but it doesn't seem to do anything. My method is below. Anyone know if what I'm trying possible, or why it's not included in DOTween already? Thanks.

    Code (CSharp):
    1.  
    2. public static class DOTweenExtensions {
    3.     // DOESN'T WORK, NOT SURE WHY
    4.     public static Tweener DOFloat(this float val, float endValue, float duration)
    5.     {
    6.         return DG.Tweening.DOTween.To(() => val, x => val = x, endValue, duration);
    7.     }
    8. }
    9.  
     
  36. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    Value vs reference.
     
  37. Trung-Hieu

    Trung-Hieu

    Joined:
    Feb 18, 2013
    Posts:
    37
    Hi guys,
    I currently have a problem with DOTween v1.2.120 (DOTweenPro 1.0.065) on Unity 2018.2.8f1.

    If I clone the project to a new folder and open Unity, after all the exports I would have this errors:
    DOTween errors.png
    In order to fix this problem, I would need to setup the DOTween like this:
    DOTween setup.png
    However, nothing has changed in Git. This is my .gitigore settings and .gitattributes settings:
    gitingore files.png
    I do not have the global gitignore files.

    Although this does not prevent me from developing the game, it does hinder Unity Cloud Build to automatically build the game. Are there any developers out there that have this problem and how would you deal with this?
     
  38. unity_ZGwWnqfUqfyfJQ

    unity_ZGwWnqfUqfyfJQ

    Joined:
    Sep 12, 2018
    Posts:
    1
    Hy! Could I drag object along the path, that I create using DoTweenPath, by mouse? I want to create something like scroll by path. Is it possible?
     
  39. XCPU

    XCPU

    Joined:
    Nov 5, 2017
    Posts:
    145
    Trying to update to the latest Pro version, but I keep getting errors like this;

    Type `Tween' does not contain a member `IsPlaying' and the best extension method overload `DG.Tweening.TweenExtensions.IsPlaying(this DG.Tweening.Tween)' requires an instance of type `DG.Tweening.Tween'

    Deleted the old one, open/close Unity etc. so dunno where i went wrong... using 2018.1.0f2
     
  40. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    I'm getting scale issues. I'm using pro version and I'm trying to punch scale the Rect Transform. But Dotween doesn't remember the original scale size.

    Dotween v1.1.640



    Code (CSharp):
    1.  
    2.  
    3.     public void PunchScaleJunk()
    4.     {
    5.         _junkIcon.GetComponent<RectTransform>().DOPunchScale(new Vector3(0.75f, 0.75f, 1), 1, 10 , 10);
    6.     }
    7.  
    8.  
     
    Last edited: Oct 1, 2018
  41. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Firstly:
    What scale is that RectTransform Component when you GetComponent on it?
    Are you sure you're passing the original scale to DoTween in that call?

    Thing the second:
    There is nothing stopping YOU from remembering the original scale size.

    I imagine it would go something like this:
    Code (CSharp):
    1. var rectTransform = GetComponent<RectTransform>();
    2.             var originalScale = rectTransform.localScale;
    3.            
    4.             rectTransform.DOPunchScale(new Vector3(0.75f, 0.75f, 0.75f), 1)
    5.                 //and here's where the magic happens :
    6.                 .OnComplete(() => rectTransform.localScale = originalScale);
    Workaround? You bet! I dunno what else you got going on in your code, but this will ipso-facto-worko.
     
    flashframe likes this.
  42. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    Good advice. And also, might want to ensure that the tween isn't being interrupted and played again before it's complete.
     
  43. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606

    Oh! Thank you! I didn't know about .OnComplete() .. I'm going to have to study up on this.
     
  44. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    It's sadly being interrupted. Each time an item is collected, the Punchscale is called. Maybe this is what's also causing the issue. I'll see if @FuguFirecracker suggestion will fix it. Which I think it will. :)
     
  45. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    If you cache the tween, you can check if it is playing already and force it to finish before calling it again :)
    But yes, using @FuguFirecracker suggestion will work. Although you might want to store the original size of the transform in Start(), otherwise you'll be taking its current size when the Tween is interrupted.
     
  46. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    @FuguFirecracker @flashframe

    This worked wonderfully, there's a small pop as the localscale reverts, but its ok. I could fix it with a vector3.Lerp or something later on.

    Thanks so much for the help, you guys are awesome!
     
    FuguFirecracker and flashframe like this.
  47. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi guys,

    Small question. Is there a way to control the yoyo interpolation? Like linear vs spline etc?

    Code (CSharp):
    1. _controlsImage.DOColor(_endColor, 1).SetLoops(-1, LoopType.Yoyo);
    Thanks!
     
  48. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    789
    You mean the easing?

    Code (CSharp):
    1. _controlsImage.DOColor(_endColor, 1).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.Linear);
     
  49. DavidNLN

    DavidNLN

    Joined:
    Sep 27, 2018
    Posts:
    90
    Hello, I can't seem to use a sequence inside of a onCollisionEnter2D method, only the last tween in the sequence is playing.
    If I take that piece of code into the start method it works fine.


    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D col)
    2.     {
    3.         Sequence mySequence = DOTween.Sequence();
    4.                    
    5.         mySequence
    6.         .Append(transform.DOMoveX(45, 1))
    7.     .Append(transform.DOMoveX(-45, 1));
    8.     }
    This only playes the second tween (Moves to -45)
    If I use the same code in the Start method instead, it works fine.

    I tried adding an if statement to check if the seq is already playing:
    Code (CSharp):
    1.    public class Example1 : MonoBehaviour
    2.    {
    3.      Sequence mySequence;
    4.    
    5.      void Start()
    6.     {
    7.          mySequence = DOTween.Sequence();
    8.     }
    9.                    
    10.    void onCollisionEnter2D(Collision2D collision)
    11.   {
    12.     if (!mySequence.isPlaying())
    13.     {
    14.          mySequence
    15.         .Append(transform.DOMoveX(45, 1))
    16.         .Append(transform.DOMoveX(-45, 1)).play();
    17.     }
    18.   }
    I also tried disabling the collision while the tween is playing, but nothing works.

    Any ideas?
     
    Last edited: Oct 7, 2018
  50. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    THAT piece of code?