Search Unity

DOTween (HOTween v2), a Unity tween engine

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

  1. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    What I'm really trying to do is generate a path for an airship (balloon on top wooden ship suspended bellow), I want it to follow the path while looking as though it's just naturally flying towards its intended destination.
    I have the path, and now I also have the heading, one last final touch would be to have it rotate lightly on the z (forward) axis, as it rotates on the y (up) axis, to simulate the force of the wooden boat below.

    Currently its movements look kind of static. While I managed to solve the other movement issue (rotate towards heading), this one I'm at more of a loss for..
    I've tried with rigid bodies and hingejoint, but paths apparently don't affect physics.
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    You mean you'd like it to tilt forward as it starts to move and then tilt back/rock slightly when it stops to give the impression of inertia? You could do that by adding separate Tweens for the z rotation and playing them at the start/stop of the ships movement.

    Is the timing of the movement controlled by player input, or is this a pre defined animation?
     
  3. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    While that could also be cool I mean that the boat should til right in a lefthand turn, and tilt left in a righthand turn, to simulate that the weight of airship below is heavy and takes a bit more force to turn around than the balloon, or some such... or perhaps it's the centrifugal force, sort of like if you spin around with a ball on a string it'll rotate outwards horizontally..
    Does that make sense? :)
     
  4. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Nothing is animated at them moment, it's all called from code.
     
  5. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Ah I see. Well you could do that through code by writing your own script that rotates the other axis of the ship based on the speed of the y-axis. Something like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Airship : MonoBehaviour {
    5.  
    6.     public float acceleration = 10f;
    7.     public float deceleration = 1f;
    8.  
    9.     float speed = 0f;
    10.     float lastY;
    11.  
    12.     void Start()
    13.     {
    14.         lastY = transform.localEulerAngles.y;
    15.     }
    16.  
    17.     void Update () {
    18.  
    19.         if(transform.localEulerAngles.y - lastY != 0)
    20.         {
    21.             speed = Mathf.LerpAngle(speed, transform.localEulerAngles.y - lastY, Time.deltaTime * acceleration);
    22.         }
    23.         else
    24.         {
    25.             speed = Mathf.LerpAngle(speed, 0, Time.deltaTime * deceleration);
    26.         }
    27.  
    28.         Vector3 newRot = transform.localEulerAngles;
    29.         newRot.x = speed;
    30.         transform.localEulerAngles = newRot;
    31.  
    32.         lastY = transform.localEulerAngles.y;
    33.  
    34.     }
    35. }
     
    Mr-Logan likes this.
  6. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    That (after a bit of tweaking) is exactly what I needed, and so simple it is. Thank you! :)
     
    flashframe likes this.
  7. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    It seems like I have to choose between either having my movement speed-based, or having my look direction set (as that requires a sequence and sequences don't allow for speed-based movement, and looking forward requires a sequence).. is there an easy way out of that conundrum? :)

    Also, I'm using Catmull Rom, and I've discovered that when I start my airship on its path it does an odd backpeddle first.
    As seen on the image:
    It was first following path 1, then it's given path 2, but it sort of doubles back inside the square, also in general it seems to have some odd movements, like at the sphere above the square it's not an entirely smooth bend.

    upload_2016-12-29_11-37-25.png

    The code for defining the points on the path is as follows:


    Code (CSharp):
    1. var path = new Vector3[]
    2.         {
    3.             transform.position,
    4.             transform.position + transform.forward * 30,
    5.             transform.position + transform.forward * 60,
    6.             Vector3.zero,
    7.             Vector3.zero,
    8.             Vector3.zero,
    9.             TargetTown.position
    10.         };
    11.  
    12.         path[3] = Vector3.Lerp(path[1], path[6], 0.25f);
    13.         path[4] = Vector3.Lerp(path[1], path[6], 0.5f);
    14.         path[5] = Vector3.Lerp(path[1], path[6], 0.75f);
    15.  
    16.         path[2] = Vector3.Lerp(path[2], path[3], 0.25f);
    17.         path[1] = Vector3.Lerp(path[1], path[2], 0.25f);
    Am I doing something horribly wrong here? (the last two, path [2] and [1] are simply to smooth out the start, as the doublingback was way worse without them).
     
  8. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    I use my own path system alongside DOTween, so not sure I can help. But if you buy the Pro version of DoTween ($15 - complete bargain) it comes with a DoTweenPath component which has settings for orientation and speed-based movement and allows you to create paths visually in the editor.

    Looking at your code though, shouldn't you be lerping from path[0] to path[6], rather than path[1]-[6] ?
     
  9. Mr-Logan

    Mr-Logan

    Joined:
    Apr 13, 2006
    Posts:
    455
    Ok, I'll look into pro. :)

    I don't think so, I want it to continue straight for a little while and then turn (just for esthetics)
     
  10. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi All.

    I have tried the DoTween Pro path feature, and while it seems to be cool, it is lacking some fine options to be really useful in actual game.

    Particularly the ease option. At the moment, they are affecting everything globally. So if your path is very long, it has undesired effect of causing the unit's speed to increase too much and not controllable in any useful way. I could set it as linear, but I would like to do things like :

    1. accelerate for some time and the decelerate only near the end of way point.
    2. do some slowdown ease when path is curving. Slowdown could depends on the angle.

    I could set the whole thing as linear and use call backs to check all the time and manually do this kind of thing, but I think this kind of feature should be added to make the feature actually really useful. The reason why I am using tween engine is so that I don't have to do manual tracking and checking this kind of thing manually on update calls.

    any ideas?
     
    BAIZOR likes this.
  11. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Also, the rigidbody shortcuts doesn't have the path options. This should be added.

    It is also worth while to point out that the path tween parameter for accepting array of vector3 is terribly inefficient in terms of gc. We should be able to somehow create non gc generating version by allowing to accept ref to the Vector3 list and maybe the waypoint count too so that we can just try and reuse the memory as much as possible.
     
    BAIZOR likes this.
  12. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I think I have found a bug in OnWayPointChange callback.

    When I play tween using say 7 way points, the callbacks are called from index 0 but it goes till index 7. This must be a bug because there is no waypoint index 7 ... it runs from [0..6] because there are only 7 waypoints.

    I am not sure what is supposed to be done with the extra waypoint index. If this is not a bug, then what is expected behaviour of this callback when I only supplied 7 waypoints? I am not running any looping.

    ---- Edit ----

    After some more experiments, I have found some more issues with the path tween.

    The condition for which callback is called is not consistent. At least it is different depends on if your starting waypoint is the same as the transform's position or not.

    If it is not the same, the callback only happens once the transform reaches its first way point. Which is understandable. Ok. so the callback is happening when transform reaches its first waypoint. Fair enough. But!

    If the transform's position is the same as the first way point, regardless of why it is it calls the callback for its previous waypoint. Ie, the transform is already its way to the next waypoint, but the callback is made for the previous waypoint.

    This is a bit difficult to explain but my expectation for callback when if the transform's position is already at the first waypoint is to either call for the next waypoint index or call it twice so that it is consistent.

    Or have the callback never calls before transform reaches its first waypoint. So that the callback is always made for the previous waypoint ( or you could say the exact waypoint ).

    I am not sure why I am seeing this difference and my only guess is that dotween adds additional waypoint internally if the transform's position is not the same as the first waypoint. This is the only explanation I can think of. It also kinda explains why there are difference in between my supplied waypoint counts and the number of callbacks the dotween is making. Also there isn't any easy way to get just how many waypoints does Dotween path tween has internally (not the interpolated ones but the ones that counts towards the callback numbers)
     
    Last edited: Jan 5, 2017
  13. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    Is it possible to store sequence or maybe the new component tweens as prefabs? or just saving them in some way.

    I'm still learning plugin sorry if question doesn't make sense.

    I'm interested in creating sequences in the editor and saving them, then within build i can access whatever sequence i want by selecting it and playing it on some objects.

    Like lets say i have text object and image object. I want to create and save 10 sequences in the editor that are used to manipulate the text and image.
    Then in build i have 10 buttons corresponding to the 10 sequences.
    Clicking a button will apply the attached sequence to the objects.

    For workflow purposes I'm looking to do that without having to code the new sequence in a new script every time. I'm still learning the visual tween component, hopefully i can save configurations as prefabs.
     
    Last edited: Jan 6, 2017
  14. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    You could do it with a single script, by wrapping your sequences in methods that take a transform (or whatever) as a parameter. So you only write the code for the sequence once, and you pass in the object you want to affect when you press your button.

    This example uses a Tween instead of a sequence, but you get the idea.

    Code (CSharp):
    1. using UnityEngine;
    2. using DG.Tweening;
    3.  
    4. public class MySequences : MonoBehaviour
    5. {
    6.     //For tweaking in the inspector
    7.     public Vector3 amplitude = 1f;
    8.     public float duration = 1f;
    9.     public Ease ease = Ease.Linear;
    10.  
    11.     public void IncrementRotation(Transform t)
    12.     {
    13.         t.DOLocalRotate(t.localEulerAngles-amplitude, duration)
    14.             .SetLoops(-1,LoopType.Incremental)
    15.             .SetEase(rotationEase);
    16.     }
    17.  
    18.     public void KillTween(Transform t)
    19.     {
    20.         DOTween.Kill(t);
    21.     }
    22. }
     
    Last edited: Jan 7, 2017
  15. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    ok thanks.
     
  16. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    Hi! Thanks for the awesome plugin.
    I'm stack with one problem, I can't move object without breaking joints and physic behaviuor. DOTweenAnimation can move Rigidbody2D object through Rigidbody2D.DOMove. But I need function Rigidbody2D.DOPath apply for the Rigidbody2D. But it doesn't exist.
    Could you explain me how to release it, or maybe you could to integrate the function to the plugin and to the DOTweenAnimation.

    Thanks in advance!
    Best regards
     
  17. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I also have mentioned about missing dopath for rigidbody in my previous post. :p
     
  18. Michael-Ryan

    Michael-Ryan

    Joined:
    Apr 10, 2009
    Posts:
    184
    Is there any way to tween a Transform position to the position of another Transform that is moving?

    If Tween 'A' is at (0,0,0) and Target 'B' is at (0,0,10) when the tween begins, and 'B' moves to (0,0,20) by the time the tween ends, Object 'A' would ultimately move along a curve from (0,0,0) to (0,0,20).

    I've used "this.transform.DOLocalMove(this.DestinationPosition, this.Duration)" to move to a specific position, but I don't understand how to update the tween while its in progress to adjust its target destination, since the destination object is moving.

    Is this possible?
     
  19. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Not sure if this is expected behaviour or has been mentioned before but I've found if you use AppendCallback multiple times in succession functions get called the wrong way round, see:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DG.Tweening;
    5. public class test : MonoBehaviour {
    6.     Sequence mySequence;
    7.     // Use this for initialization
    8.     void Start () {
    9.             mySequence.Kill (false);
    10.             mySequence = DOTween.Sequence ();
    11.             mySequence.AppendCallback (One);
    12.             mySequence.AppendCallback(Two);
    13.             mySequence.AppendCallback (Three);
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.  
    19.     }
    20.  
    21.     void One(){
    22.         Debug.Log("one");
    23.     }
    24.  
    25.     void Two(){
    26.         Debug.Log("two");
    27.     }
    28.  
    29.     void Three(){
    30.         Debug.Log("three");
    31.     }
    32.  
    33. }
     
  20. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    Hi Guys,

    I'm using the latest DOTween and the SpriteRenderers shortcuts doesn't work. The other shortcuts (like Camera.backgroundColor) are working just fine. Any ideas what's going on?

    Code (CSharp):
    1. error CS1928: Type `UnityEngine.SpriteRenderer' does not contain a member `DOColor' and the best extension method overload `DG.Tweening.ShortcutExtensions.DOColor(this UnityEngine.Material, UnityEngine.Color, float)' has some invalid arguments
     
  21. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Hi. Your error is kinda pointless without seeing the code what actually caused the error.
    Code (CSharp):
    1. .backgroundColor
    is not a DoTween shortcut.
    Code (CSharp):
    1. Camera.backgroundColor
    That works?
    That's suprising. I would expect
    Code (CSharp):
    1. Camera.main.backgroundColor
    or
    Code (CSharp):
    1. Camera.current.backgroundColor
    to work...
    But certainly not:
    Code (CSharp):
    1. Camera.backgroundColor
    At any rate,
    Code (CSharp):
    1.     var spriteRenderColorTweener = new SpriteRenderer().DOColor(Color.yellow, 1f);
    Certainly does work
     
  22. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    The error is not that pointless as you may think, Fugu. It says
    - so it means the SpriteRenderer doesn't have a member DOColor (and that's the shortcut for color tweening).

    The sprite color shortcut should be used like this:
    Code (csharp):
    1.  
    2. SpriteRenderer s = GetSprite(); // GetSprite is a function returning a given sprite
    3. s.DOColor(color, 1f);
    4.  
    Your code certainly doesn't work on my end - I get the same exact error.

    And sorry for being not clear enough, actually it was a typo as it should be:
    I tried to reimport the newest version of DOTween and still the SpriteRenderer shortcuts don't work.

    Any help would be much appreciated.
     
  23. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    It would definitely help to see the code that's causing the error. Silly question, but you've included the DG.Tweening namespace, right? What version of Unity are you using? This works for me in 5.4:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using DG.Tweening;
    4.  
    5. public class SpriteRendererTween : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.  
    10.         SpriteRenderer s = GetComponent<SpriteRenderer>();
    11.         s.DOColor(Color.blue, 0.5f).Play();
    12.    
    13.     }
    14. }
     
  24. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    You're right flashframe, but actually the piece of code I'm using is so simple that it's very unlikely I could mess something up:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using DG.Tweening;
    4.  
    5. public class FogOfWarCell : MonoBehaviour {
    6.  
    7.     public SpriteRenderer[] CloudSprites;
    8.  
    9.  
    10.     public void FadeIn(float a = 1f){
    11.        
    12.         for(int i = 0; i < CloudSprites.Length; i++){
    13.             SpriteRenderer s = CloudSprites[i];
    14.             s.DOColor(a, 1f);
    15.        
    16.            
    17.         }
    18.     }
    19. }
    20.  
    Your code isn't working as well, so I'm assuming there is something wrong with my project setup.
    I'm using 5.3.5p1 - my client requires this version so I'm stuck with it. However I created an empty project and the shortcuts are working perfectly fine. So it's pretty clear to me there is something wrong with the project setup.

    Thanks for your help guys.
     
  25. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    If anyone is interested: deleting and reimporting the library didn't help. But when I've imported an older version of DOTween (1.1.135), and later imported the newest version - everything worked like a charm.
     
  26. j-washington2

    j-washington2

    Joined:
    Dec 4, 2015
    Posts:
    1
    Hey, I was wondering if DOMoveX is supposed to prevent movement along the Y axis in 2D? I've noticed that adding a line using either that DOMoveY prevents most movement along the opposite axis except in cases of very strong physics forces.
     
  27. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    @priotrO Reading the full error message reveals the error: you have invalid argument types. You likely meant DOFade instead of DOColor.

    @j-washington2 I don't think it prevents it. However, normally you wouldn't directly manipulate positioning of a physics object like that.
     
  28. m_knight_jul

    m_knight_jul

    Joined:
    Jan 25, 2017
    Posts:
    5
    Hello,

    I am using DOTween to move enemies alongside predefined paths for a 2.5D shmup.
    While creating a path and moving an enemy at a constant speed is fairly simple, I find myself at a loss when it comes to compensating for the default EaseTypes' shortcomings whenever my movement speed must vary.

    One of the movement types I want is a fast beginning and ending, with the enemy slowing down in the middle. None of the default EaseTypes are able to provide this. As a result, I tried to look up alternatives and came across the notion of Cubic Béziers.
    The following Cubic Bézier matches the type of movement I want :
    http://cubic-bezier.com/#.37,.94,.83,.04
    However, I can't see how exactly I am supposed to input those four Cubic Bézier points to my DOPath() call. No method nor option for Cubic Bézier inputs seem to exist.

    In that case, I thought I could create a new custom EaseType that could easily be given as a parameter to SetEase(), but the documentation does not explain how I can do this.

    So my question is : how can I implement that custom EaseType based on my four cubic Bézier points? Is there another easier way to provide those four cubic points to the DOPath() call?

    Thanks in advance.
     
  29. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    What you're looking for is an AnimationCurve I think.

    https://docs.unity3d.com/ScriptReference/AnimationCurve.html

    You can create a public variable in your script that will create an editable animation curve in the editor that you can customise to get the effect you want.

    Code (CSharp):
    1. public AnimationCurve myCurve;
    DoTween accepts an AnimationCurve as a parameter of SetEase(), so instead of SetEase(Ease.Linear) for example, you'd say

    Code (CSharp):
    1. .SetEase(myCurve);
    This is the sort of curve I think you want to draw:

     
    Last edited: Jan 25, 2017
  30. m_knight_jul

    m_knight_jul

    Joined:
    Jan 25, 2017
    Posts:
    5
    Thanks for the advice!

    That said, is there a way to do without AnimationCurves? As some of my movements actually use the linear EaseType and because all the enemy movements are triggered by the same line of code, I would rather avoid having to check every single time whether it is supposed to use an EaseType or an AnimationCurve. The theoretical best solution for me would be to have the ability to create additional custom EaseTypes with those four cubic bézier points, so that I can select them as the SetEase() parameter.

    Is that possible?
     
  31. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    I don't really follow the problem. Can you share some code to make it clearer?
     
  32. m_knight_jul

    m_knight_jul

    Joined:
    Jan 25, 2017
    Posts:
    5
    Sure thing :

    Code (CSharp):
    1. enemy.GetComponent<Enemy>().tween = enemy.transform.DOPath(getCurrentEnemySpawnData().movementData.path, getCurrentEnemySpawnData().movementSpeed, PathType.CatmullRom, PathMode.Full3D, 10,null).SetSpeedBased(true).SetEase(getCurrentEnemySpawnData().easeType);
    All my enemies are spawned at set moments depending on data contained in an List. That list itself contains objects of the EnemySpawnData class. It is this class that contains the easeType that the given enemy should use for its movement as well as the path to follow itself.

    Creating a custom easeType would make no difference to this enemy spawning function, and I would only have to select this custom easeType when I edit the enemySpawnData related to this specific enemy.
     
  33. adentutton

    adentutton

    Joined:
    Mar 24, 2013
    Posts:
    34
    Hey guys!

    This asset looks really great! Im trying to find something which can simulate a 2D ball movement? At the moment my basic tween moves at speed to one point but scales linearly to the mid point and then back to normal size at the target! Not very realistic! Can you also control the speed of the movement of the object to the target point?

    Thanks in advance!
     
  34. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    @m_knight_jul You can write custom easing functions like this
    Code (csharp):
    1.  
    2. transform.DOMove(new Vector3(1, 1), 1).SetEase(customEase);
    3.  
    4. float customEase(float d, float t, float a, float b) => {
    5.   return d / t;
    6. }
    7.  
    If you need additional parameters, you could do something like this
    Code (csharp):
    1.  
    2. transform.DOMove(new Vector3(1, 1), 1).SetEase(customEase(1, 2, 3, 4));
    3.  
    4. EaseFunction customEase(float p1, float p2, float p3, float p4) {
    5.    return (float d, float t, float a, float b) => {
    6.      return d / t;
    7.    };
    8. }
    9.  
    @adentutton Look into SetEase()
     
    HEATH3N likes this.
  35. m_knight_jul

    m_knight_jul

    Joined:
    Jan 25, 2017
    Posts:
    5
    Thanks for the EaseFunction examples!
    That said, the samples here mimic the extremely basic Linear EaseType so I had to fiddle with them in order to work with Cubic Bézier points.

    As a test, I have the following code :
    Code (CSharp):
    1. enemy.GetComponent<Enemy>().tween = enemy.transform.DOPath(getCurrentEnemySpawnData().movementData.path, getCurrentEnemySpawnData().movementSpeed, PathType.CatmullRom, PathMode.Full3D, 10, null).SetSpeedBased(true).SetEase(customEase(0.37f, 0.94f, 0.83f, 0.04f));
    Code (CSharp):
    1. EaseFunction customEase(float p1, float p2, float p3, float p4)
    2.     {
    3.         return (float d, float t, float a, float b) =>
    4.         {
    5.             float i1 = Mathf.Lerp(p1, p2, t);
    6.             float i2 = Mathf.Lerp(p2, p3, t);
    7.             float i3 = Mathf.Lerp(p3, p4, t);
    8.             float j1 = Mathf.Lerp(i1, i2, t);
    9.             float j2 = Mathf.Lerp(i2, i3, t);
    10.             return Mathf.Lerp(j1, j2, t);
    11.         };
    12.     }
    However, this does not seem to properly work as the 't' value stays the same, and my enemies are frozen in their initial position on the tween. Did I miss something?
     
  36. mikatu

    mikatu

    Joined:
    Aug 3, 2015
    Posts:
    28
    Indeed d is for the time passed and t is a constant for the total time. I don't get your example but you would need 'd / t' to calculate the curves.
     
  37. alekschekhov

    alekschekhov

    Joined:
    May 5, 2014
    Posts:
    23
    Hi!

    I've recently bought Pro version of your product. First of all I would like to say thanks for the great job you did. Everything is easy to use, the performance is great and etc. :).

    The only question that I have is about the possibility to make instant animations.
    Let me explain myself: I've some game objects that are moving/scaling/rotating using DOBlablabla... and there is an option for the end user to turn off the animations for the game, to get the possibility to move/scale/rotate game objects instantly. Some of my game logic is using tween callbacks, so I would like to still use all the animation sequences that I have, but with objects instant moving/rotating/scaling. What is the best approach to do this? I've thought about some dummy things like setting DOTween timeScale to some big value like 9999999 or setting duration to something really small like 0.00000001f. Maybe there is some elegant way to do this? Sorry if I'm missing something really obvious here :).

    Thank you!
     
  38. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    If you cache your sequences, then you just need to call Complete(true) on them. This will send them to their end position and call any internal callbacks.

    http://dotween.demigiant.com/documentation.php#controls
     
  39. alekschekhov

    alekschekhov

    Joined:
    May 5, 2014
    Posts:
    23
    @flashframe, yes, I'm caching my sequences and your option could solve my problem. But I'm caching sequences to have a possibility to complete previous sequence, if such exists, before starting new on the same game object.

    So, to start a new sequence on game object I'm doing something like:

    Code (CSharp):
    1. card.CompletePreviousAnimation (() => {
    2.                     card.AppendTween (card.SortingOrderTween (i));
    3.                     card.AppendTween (card.MoveTween (card.Position + (undo ? Constants.Vector3Consts.Right : Constants.Vector3Consts.Left) * _stockCardsSpacing, _moveDuration));
    4.                 });
    Method "CompletePreviousAnimation" looks like:

    Code (CSharp):
    1.  public void CompletePreviousAnimation (System.Action done) {
    2.             // Check if sequence exists and it's playing
    3.             if (_animationSequence != null && _animationSequence.IsPlaying ()) {
    4.                 _animationSequence.Complete (true);
    5.             }
    6.             _animationSequence = DOTween.Sequence ();
    7.             if (done != null) {
    8.                 done ();
    9.             }
    10.         }
    And "AppendTween" is just (also I've "JoinTween", "AppendCallback" and etc.):

    Code (CSharp):
    1. public void AppendTween (Tween t) {
    2.             _animationSequence.Append (t);
    3.         }
    So, if I will try your option, I probably should disable "autoPlay" on the DOTween, to prevent any chance of some sort of "visible animations". Because there might some frame delays between sequence playing and me completing them right away. And I probably should get some sort of my own Play method: the animated one will simply play the sequence and non-animated one, will just complete the sequence.

    What do you think?

    Thank you!
     
  40. McSwan

    McSwan

    Joined:
    Nov 21, 2013
    Posts:
    129
    Hi,

    I can't seem to find the method or documentation to tween to a moving transform. Can someone link to to where it is in the documentation.
     
  41. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    here: http://dotween.demigiant.com/
     
  42. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Maybe this author of Dotween doesn't come here anymore..
     
  43. alekschekhov

    alekschekhov

    Joined:
    May 5, 2014
    Posts:
    23
    Yeah, I really would like to hear some options for my case from him.
     
  44. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    He's on Twitter @demigiant
     
  45. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    I would like to have three tweens appear to play at the same time. I expect this is not coded correctly... suggestions?

    Code (CSharp):
    1.   Sequence mySequence = DOTween.Sequence();
    2.   mySequence.Append(go.transform.DOMove(go2.transform.position, 5f).SetEase(Ease.OutQuint).SetLoops(1))
    3.   .Insert(0, mat.DOColor(new Color(1f, 1f, 1f, 0), "_EmissionColor", 5f).SetLoops(1))
    4.   .Insert(0,nucleus.transform.DOScale(75f, 5f).OnComplete(()=>completionFunction())
    5.   );
    6.   mySequence.Play();
    The color and scale appear to work but not the Move
     
  46. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    When I set up sequences, I just always use Insert instead of Append. Like this:

    Code (CSharp):
    1. Sequence mySequence = DOTween.Sequence();
    2.   mySequence.Insert(0,go.transform.DOMove(go2.transform.position, 5f).SetEase(Ease.OutQuint).SetLoops(1))
    3.   .Insert(0, mat.DOColor(new Color(1f, 1f, 1f, 0), "_EmissionColor", 5f).SetLoops(1))
    4.   .Insert(0,nucleus.transform.DOScale(75f, 5f).OnComplete(()=>completionFunction())
    5.   );
    6.   mySequence.Play();
    That works for me.
     
  47. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    @flashframe Thanks for the suggestion. I had tried that as well after I posted and upon further inspection and commenting out the DOColor and DOcale changes and just trying a single DOTween I can see it is having a problem with just the DOMove.

    Something odd going on. I called DOTween.Clear() just before I output a debug statement

    go pos => (0.0, 1.5, -1.7) go2 pos => (0.0, 0.0, 0.0)

    Code (CSharp):
    1. go.transform.DOMove(go2.transform.position, 5f).SetEase(Ease.OutQuint).SetLoops(1);
    I do see the object start to move but something is interrupting the movement.

    Is there any way to debug a DOTween?
     
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Ahoy!

    I admit I don't come here often anymore, because now that the DOTween's user base has increased quite a lot, I am already overwhelmed by support emails (whew) and I see that you're helping each other here which is great (and big big thanks to all of you helping) :)

    Let me see if I can help a little too...

    @ibyte The reasons why a tween might be interrupted are usually these:
    1. you killed it
    2. something else is blocking your tween's target
    3. your tween was automatically killed because your target became null, or something like that
    To debug, one trick is to disable safe mode. That way, if something bad happens during a tween's life, the tween won't be automatically killed, and instead it will start throwing errors, which should help you understanding where the problem was.
    Your code seems ok, so I assume the problem might be there, or in point 2.

    @euphere Uhm, your use case is pretty interesting. I honestly never thought of such a situation, but in theory, setting DOTween.timeScale to a high value seems like a viable trick. Otherwise also setting the duration to a very small value, but I suggest the former (also easier to maintain). I have to admit you're in the world of experimentation though.
     
  49. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi @Izitmee while you're here could you tell me if this is the expected behaviour, a bug, or I'm doing something wrong . The following code prints 3, 2, 1 rather than 1,2,3

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DG.Tweening;
    5. public class test : MonoBehaviour {
    6.     Sequence mySequence;
    7.     // Use this for initialization
    8.     void Start () {
    9.             mySequence.Kill (false);
    10.             mySequence = DOTween.Sequence ();
    11.             mySequence.AppendCallback (One);
    12.             mySequence.AppendCallback(Two);
    13.             mySequence.AppendCallback (Three);
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.     }
    19.     void One(){
    20.         Debug.Log("one");
    21.     }
    22.     void Two(){
    23.         Debug.Log("two");
    24.     }
    25.     void Three(){
    26.         Debug.Log("three");
    27.     }
    28. }
     
  50. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    @wxxhrt Ahoy! That's an important thing about callbacks. Sequences are time-based, and everything that happens at the same exact moment has no guaranteed order (because the only true order between same-type operations is time). If you want those callbacks to happen in the order you expect, use an Insert with a minimal time (0.0001f for example).