Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

DOTween (HOTween v2), a Unity tween engine

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

  1. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    281
  2. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    251
    didnt know where to ask but here.I use LookRotation to make a cube look at the previous one thus making a wall

    Code (CSharp):
    1.             dir = lastPoint - point;
    2.             dir.y = 0;
    3.             go.transform.rotation = Quaternion.LookRotation(dir);
    but it doesnt work. It works though if i use DORotateQuaternion with a time value higher than 0. Why?
     
  3. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
  4. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @Liminal-Ridges If it's because the rotation doesn't seem right, please try to install the update I posted on the last message. I introduced a bug to fix another very rare bug, but this version should fix it.
     
    JesterGameCraft likes this.
  5. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    281
    Thanks @Demigiant. I'll check it out. Regards...
     
  6. NINPO

    NINPO

    Joined:
    Jun 21, 2015
    Posts:
    6
    Hello, I was wondering if it was possible to create a tween from an animationcurve that begin at a specific value of the curve and make the tween follow the curve until the end ?
     
  7. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    You could tween a float value and use that to sample the curve using AnimationCurve.Evaluate. Quick example:

    Code (CSharp):
    1.  
    2. float curveTime = 0f; //the start point on your curve
    3. // Tween to end of curve
    4. DOTween.To(()=> curveTime, x=> curveTime = x, 1f, 1f).OnUpdate(EvaluateCurve);
    5.  
     
  8. Balphagore

    Balphagore

    Joined:
    Jul 18, 2019
    Posts:
    77
    Perhaps this problem has already arisen here. DOTweens partially fails when using assembly definitions.
    I use 2020.3.35f1 and assembly definitions. Outside of definition, all DOTweens modules work correctly. But not everything works inside the definition. For example, SpriteRenderer.DOColor just in the scripts folder works fine, but from inside the definition gives an error:

    Code (CSharp):
    1. Severity    Code    Description    Project    File    Line    Suppression State
    2. Error    CS1929    'SpriteRenderer' does not contain a definition for 'DOColor' and the best extension method overload 'ShortcutExtensions.DOColor(Camera, Color, float)' requires a receiver of type 'Camera'    Game    D:\Software\Projects\merge-bounty\Assets\Scripts\Game\MarkersSystem.cs    29    Active
    3.  
    Moreover, the error occurs immediately in Visual Studio, even before compiling and switching to the Editor.
     
  9. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    281
    Please see Update2 below for final findings. The issue is in OnStepComplete and is not related to timeScale, timeScale only amplifies it.

    I was going to say that this timeScale is the best thing since sliced bread but there are issues that it causes. Or perhaps I'm doing something wrong. I spent a whole day debugging this issue which was hard to reproduce and finally got a luck debug trace. The tweener that I'm using looks like this:

    Code (CSharp):
    1.  // fades in and out the bar
    2.         barAlphaTween = canvasGroup.DOFade(1, alphaTime).SetEase(Ease.Linear).SetAutoKill(false).Pause()
    3.                                 .SetLoops(-1, LoopType.Yoyo).OnStepComplete(OnAlphaComplete);
    4.  
    5.  // each time a loop step completes we pause it, the stops don't stop exactly
    6.  // at 0 and 1 alpha values so we check which it is against 50% and set it
    7.     void OnAlphaComplete()
    8.     {
    9.         Debug.Log("Alpha value " + canvasGroup.alpha);
    10.  
    11.         barAlphaTween.Pause();
    12.  
    13.         // bar was being faded out
    14.         if (canvasGroup.alpha < 0.5f)
    15.         {
    16.             // set actuall 0 value since it's never perfectly 0
    17.             canvasGroup.alpha = 0;
    18.             canvas.enabled = false;
    19.         }
    20.         else   // bar is fully visible
    21.             canvasGroup.alpha = 1;
    22.     }
    23.  
    24. // also a bit of ShowBar relevant code to barAlphaTween
    25. // sets the bar visible or invisible
    26.     public void ShowBar(bool val, bool immediate = false)
    27.     {
    28.         if (immediate)
    29.             barAlphaTween.timeScale = 20f;
    30.         else
    31.             barAlphaTween.timeScale = 1f;
    32.  
    33.             barAlphaTween.Play();
    34.     }
    35.  
    36.  
    Basically it controls the alpha of a canvas group. I reuse this tweener each time I want to fade in/out the bar and it works. When I increase the timescale however the alpha value gets less and less from the endValue when the tweener completes.

    For example with scale set at 1 on tween complete:

    - show bar -> Alpha value 0.4721867 // after 20+ iterations OR very high # I hit this
    - hide bar -> Alpha value 0.2493782
    - etc...

    If I set the timeScale to 5 for example on tween complete then I will get error as such:

    - show bar -> Alpha value 0.7534218
    - hide bar -> Alpha value 0.5199378 // after 60+ iterating I hit this, expect to be below 50% at least
    - etc...

    And if I set the timeScale to say 20 on tween complete then I will get errors as such:

    - show bar -> Alpha value 0.788449
    - hide bar -> Alpha value 0.5453925 // after 60+ iterations I hit this

    The amount of iterations I need to do the bar show/hide appears be different with each execution but usually after about 60+ iterations to hit. Also I give it 5 seconds between show/hide bar which should be plenty of time for it to complete and they do. From example above it looks like timeScale has nothing to do with this, but in practice I found that if I increase the time scale value I increase the rate at which above occurs.

    Because of my assumption that value of the alpha should be at least above or below 50% when tween completes I get into trouble when that is not true. I'll most likely rewrite my code not to rely on this at all but there should be a warning in doc I think, that says that if you increase timeScale too high then you're not guaranteed to hit your specified endValue at the end of a tween loop. If you see anything that I'm doing wrong please let me know. Maybe OnStepComplete stops in the wrong spot? Perhaps this behaviour is as per design, but if it is it should be documented somewhere. It is very intermittent and hard to reproduce so I'm hoping this will save someone some time. Also, in my test I increased Time Scale in unity to execute them faster anywhere from 5 to 23, with higher value the issue is seen sooner but I suspect it has to do with unity time resolution being larger.

    Update: I've ran the same test with OnUpdate present to see the value of the alpha as it changes during the tween. Here is one failure example where we are moving from full alpha 1 to 0 (unity Time Scale set to 23 during the test). The values I got are:

    0.7815115 // good
    0.2273428 // good
    0.04131013 // good
    0.5382918 // bad (target is 0 so this is moving in wrong direction now back to 1 looks like)

    The 0.5382918 value is also reported by the OnStepComplete. So what I think is happening is that when OnStepComplete ends it might be reporting the next value of the loop going back in the opposite direction, where it should be reporting the last value of the tween moving in the instructed direction (ie. 0.04131013). When timeScale is increased this extra reported value in the opposite direction can be very large and that is why I think I'm getting my strange behaviour. If OnStepComplete only reported the proper value (last value in the current direction of the loop) I think that would fix the problem.

    Update2: After running more tests this issue appears to be with OnStepComplete. Even at time scale of 1 in DoTween it still happens. To reproduce run a tween like I have listed at the top of this post with OnUpdate included to print out tween values as it moves through each step. You'll see that when OnStepComplete is called the current value (of what is being tweened) is not actually the smallest or largest (depending on which direction of the loop you're tweening). The example from previous update illustrates this. Let's say you are tweening to 0 value and are printing current value in OnUpdate, then I will get:

    0.7815115 // good
    0.2273428 // good
    0.04131013 // good
    0.5382918 // bad (OnStepComplete is called here and not on previous value)

    When OnStepComplete calls and I print out the current value I get 0.53822918 but I should get 0.04131013. The value of 0.53822918 is pretty extreme and not seen very often but it does happen. Most of the time the values are much smaller for example last value would be 0.143234234 instead of 0.53822918 but is still wrong. I hope this clarifies the issue, let me know if you have any questions.

    On a separate note I converted my single tween with a yoyo loop to two tweens, one for showing the bar and one for hiding it. I executed my test with timeScale of 20 and Unity Time scale at 23 over 9000 iterations and have not seen a single problem. That's the solution I'm going with for now.
     
    Last edited: Oct 29, 2022
  10. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    281
    Another question. I'm using camera shake, my tween looks like so:

    Code (CSharp):
    1.             cameraShake = cm.DOShakePosition(1f, new Vector3(0.1f, 0, 0), 20, 70, false, ShakeRandomnessMode.Harmonic)
    2.                                                 .Pause().SetAutoKill(false);
    When I play it it works great. However I want to later reuse this tween, so I tried using ChangeStartValue. I tried passing in the cm.transform.position, cm.transform but am getting an error that it expect vector3[], so looking for an array? Documentation just says newStartValue (guess it depends on what is being tweened). Do I need to pass in a vector3 array, like position, rotation?
     
    Last edited: Nov 6, 2022
  11. Bongmo

    Bongmo

    Joined:
    Jan 18, 2014
    Posts:
    155
    I've a SetSpeedBased() question.

    My code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DG.Tweening;
    5.  
    6. public class DoTweenObjectMove : MonoBehaviour
    7. {
    8.     public Transform targetObject;
    9.  
    10.     public float objectSpeed = 1F;
    11.  
    12.     public float speedActual = 1F;
    13.  
    14.     private Vector3[] wayPoints = new[] {
    15.             new Vector3(0f, -4f, 20f),
    16.             new Vector3(0f, 0f, 1f),
    17.             new Vector3(0f, -4f, 14f),
    18.             new Vector3(0f, 0f, 40f),
    19.             new Vector3(0f, -4f, 27f),
    20.             new Vector3(0f, 0f, 39f)
    21.         };
    22.  
    23.     void Start()
    24.     {
    25.         ObjectStart();
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.         speedActual += 2 * Time.deltaTime;
    31.  
    32.         objectSpeed = speedActual;
    33.     }
    34.  
    35.     private void ObjectStart()
    36.     {
    37.         targetObject.DOPath(wayPoints, objectSpeed, PathType.CatmullRom, PathMode.Full3D, 10, Color.blue)
    38.             .SetLookAt(lookAhead: 0.1f)
    39.             .SetSpeedBased(true)
    40.             .SetEase(Ease.Linear);
    41.     }
    42. }
    The tween is the same. Changing objectSpeed has no effect.
    I want to change the objectSpeed.

    Is this not possible in DOTween?

    Sorry. I'm new to DOTween.

    Thank you for any help.
     
  12. Pinsukka

    Pinsukka

    Joined:
    Feb 17, 2014
    Posts:
    15
    How do you use DOTween with for loops? Mine seems completely broken, here's an example:

    Code (CSharp):
    1. for(int i = 0; i < count; i++)
    2. {
    3.     DOTween.To(() => valueArray[i], x => valueArray[i] = x, targetArray[i], 2f);
    4. }
    By doing this the index that gets tweened is just wrong, sometimes it even goes over the loop and seems to use count +1 as the indexer and thus gives me an index out of range error. I can do this manually by typing each index into its own line just fine, so how come the loop doesn't work?

    I've had this problem for ages, but I've always been too lazy to ask about it and just went with the manual route. This time though, that's not really an option, so I would like to know if I'm doing something wrong or if it's a bug?

    Thanks!

    Edit: To clarify, tweening seems to start as if "i" was 1 instead of 0. If I set the value of count to 1, the loop should run ONCE with index 0, but DOTween uses index 1 for some reason. I tried to set i = -1 and count to 0 instead, but then I'm getting an error (which should obviously happen).

    I also tried this with Sequence with Insert function inside the for loop, but the problem persists.

    Edit 2: Ok, it seems that wrapping the DOTween.To function inside coroutine fixes the issue. Like so:
    Code (CSharp):
    1. for(int i = 0; i < count; i++)
    2. {
    3.     StartCoroutine(DoTo(i));
    4. }
    5.  
    6. IEnumerator DoTo(int i)
    7. {
    8.     DOTween.To(() => valueArray[i], x => valueArray[i] = x, targetArray[i], 2f);
    9.     yield return null;
    10. }
    I'm still curious what's causing this though, it's a weird problem!
     
    Last edited: Nov 4, 2022
  13. ExobotsDeveloper

    ExobotsDeveloper

    Joined:
    Feb 16, 2022
    Posts:
    6
    Hi !, when create sequence like this :

    Code (CSharp):
    1. deadSequence.Append(deadObject.transform.DOPunchScale(_minimizeScale / 4, 0.3f)
    2.     .OnComplete(OnDeadSequencePunch));
    3.  
    4. deadSequence.Append(deadObject.transform.DOScale(_minimizeScale, 0.1f));
    5. deadSequence.SetAutoKill(false);
    the complete method is executed when I have not told it to .play(), just add it to the sequence, has anyone faced this before?

    Fix: Pause the tween when you create it
     
    Last edited: Nov 4, 2022
  14. SceneForgeStudio

    SceneForgeStudio

    Joined:
    Feb 28, 2017
    Posts:
    446
    I've been using DoTween for a while in my project and it's been great! I now want to use it's Transform.DoPath functionality for NPC waypoints (not using any navmesh or anything). I want to make the Animation match the movement of the path. I'm using Unity's StandardAssets character animator, that has "Forward" and "Turn" variables.

    Is it possible to somehow set these variables to match the motion of the path's movement?
     
    Last edited: Nov 9, 2022
  15. ShakeTheAi

    ShakeTheAi

    Joined:
    Dec 12, 2018
    Posts:
    12
    Hello
    Thank you for making this an amazing asset. I have a problem with the tween animation. I'm not a programmer but I do visual scripting, so here's the detail:
    There's a Sphere and Tween attached to it with these settings.
    https://imgur.com/a/W5QdMAs

    The sphere rotates in a circle anticlockwise with -1 loop (infinite).

    when the Button is pressed I execute a Method called "DOTweenAnimation.DoPlayForward"
    When the other button is pressed I execute the Method called
    "DOTweenAnimation.DoPlayBackwards"

    The problem is the loop animation works fine but when I press the Forward button the animation stops (after doing 1 loop) at the starting point It won't loop, even the tween animation setting is set to Loops -1 which is infinite.
    Please tell me what I'm doing wrong here...

    here's the video



    regards
     
  16. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,796
    Hi there

    Assuming I have an array of colors, how do "tween" assign those colors one by one and then after last color start from the first?

    For example, If I have Red, Blue and Green
    Start with green, after 10 seconds change to blue in 5 seconds, then wait 10 seconds, then change to Green in 5 seconds, then wait 10 seconds then change into Red and it goes on

    I'm using DoTween Pro

    Please advise?
     
  17. rsauchuck-gp

    rsauchuck-gp

    Joined:
    Jan 21, 2020
    Posts:
    16
    I am having an issue scaling some instantiated prefabs in my project. I have a Dictionary that contains references to the prefabs. I want to change in scale the currently "unselected" prefab but nothing happens. I can control whether they are active and I can DOMoveX but DOScale fails

    Code (CSharp):
    1.     public void ActivateSelectedPrefab(string prefabName)
    2.     {
    3.         foreach (var trackedPrefab in _instantiatedPrefabs)
    4.         {
    5.        
    6.             if (trackedPrefab.Key == prefabName)
    7.             {
    8.                 // do nothing
    9.             } else
    10.             {
    11.                 //_instantiatedPrefabs[trackedPrefab.Key].SetActive(false);
    12.                 _instantiatedPrefabs[trackedPrefab.Key].transform.DOScale(0.2f, 1);
    13.                 //_instantiatedPrefabs[trackedPrefab.Key].transform.DOMoveX(0.3f, 1);
    14.             }
    15.         }
    16.     }
    RESOLVED: I forgot to mention I am using Unity's AR Foundation tools. Turns out I needed to disable the ARScaleInteractable component on my GOs , do the tweens, and then reenable the component with a callback onComplete
     
    Last edited: Nov 19, 2022
  18. ashlukechloe

    ashlukechloe

    Joined:
    Feb 7, 2021
    Posts:
    2
    Hi, just bought Pro and am having a play. I have a Windmill prefab gameObject, which consists of a pole and some sails. I put a DotweenAnimation on the Sails. Works lovely. Now I have a prefab 'parent' which has a collection of these windmills (~20 instances) and that prefab is replicated multiple times. If the 'parent' object gets its OnBecame(In)visible called I want to enable/disable the DOTweenAnimation on any child objects so it's not rotating the sails of anything that is not visible....but I can't find a DOTweenAnimation.stop so I suspect I am approaching it the wrong way. I'm also not sure what the Add Manager button does (well, I can see it adds a Manager!). Does that need to exist?
     
  19. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    72
    Dumb question, what's the proper way to tween at a constant? `SetSpeedBased(true);` is still slowing down towards the end.
     
  20. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    Check the ease of your tween. (Needs to be Ease.Linear)
     
    jmgek likes this.
  21. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    154
    Try it like this:
    Code (CSharp):
    1. for(int i = 0; i < count; i++)
    2. {
    3.     int index = i;
    4.     DOTween.To(() => valueArray[index], x => valueArray[index] = x, targetArray[index], 2f);
    5. }
     
  22. ashlukechloe

    ashlukechloe

    Joined:
    Feb 7, 2021
    Posts:
    2
    Seems to be working now, without a Manager, still not sure what that does!
    I used a cullingGroup on the parent object, when it was out of sight I iterated the DOTWeenAnimation children and used DOPause, then DOPlay when it comes back in to sight.
     
  23. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    394
    I am running into an issue. This DoTween sequence plays every step sequentially, and I want it to play them ALL simoultaneously:


    Code (CSharp):
    1.     public void DealCards(int numberToDeal)
    2.     {
    3.         //TODO: Add animations
    4.         if (DrawPile.Count <= numberToDeal)
    5.         {
    6.             AddDiscardBackIntoDrawPile();
    7.         }
    8.         Vector3 startPosition = new Vector3(-Screen.width / 2f + 50f, DrawPileCardBackGameObject.GetComponent<RectTransform>().sizeDelta.y + 50f, 0f);
    9.         HandCardObjects = new List<GameObject>();
    10.         HandCards = DrawPile.Count > numberToDeal ? DrawPile.GetRange(0, numberToDeal).ToList() : DrawPile;
    11.         for (int x = 0; x < HandCards.Count; x++)
    12.         {
    13.             CardData card = HandCards[x];
    14.             GameObject cardObjectGameObject = new GameObject();
    15.             cardObjectGameObject.name = $"CardSlot{x}";
    16.             cardObjectGameObject.transform.parent = Hand.transform;
    17.             cardObjectGameObject.transform.localPosition = startPosition;
    18.             cardObjectGameObject.transform.localRotation = Quaternion.Euler(0, 0, 180f);
    19.             cardObjectGameObject.transform.localScale = new Vector3(0, 0, 0);
    20.             CardObject cardObject = cardObjectGameObject.AddComponent<CardObject>();
    21.             cardObject.FinalPosition = new Vector3(CardObject.CardPositions[x].x, CardObject.CardPositions[x].y, 0);
    22.             cardObject.Initialize();
    23.             cardObject.Card.Title = card.Name;
    24.             cardObject.Card.Description = card.Description;
    25.             cardObject.Card.CardCost = card.ActualEnergyCost.ToString();
    26.             if(CardObject.CardPositions[x].x <= 0)
    27.                 cardObjectGameObject.transform.SetSiblingIndex(0);
    28.             else if(CardObject.CardPositions[x].x > 0)
    29.                 cardObjectGameObject.transform.SetSiblingIndex(x);
    30.             HandCardObjects.Add(cardObjectGameObject);
    31.         }
    32.         StartCoroutine(DealCardsAnimation());
    33.     }
    34.  
    35.  
    36.   public IEnumerator DealCardsAnimation()
    37.     {
    38.         float duration = 1.5f;
    39.         foreach (GameObject card in HandCardObjects)
    40.         {
    41.             CardObject cardData = card.GetComponent<CardObject>();
    42.             Sequence seq = DOTween.Sequence();
    43.             seq.Append(card.transform.DOLocalMove(cardData.FinalPosition, duration));
    44.             seq.Append(card.transform.DOLocalRotate(new Vector3(0, 0, 0), duration));
    45.             seq.Append(card.transform.DOScale(new Vector3(1f, 1f, 1f), duration));
    46.             seq.Play();
    47.         }
    48.         yield return null;
    49.     }
    It plays them correctly, just one after another. I looked everywhere online and this is supposedly how you are supposed to get the tween animations to play async/all at once, right?
     
  24. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    You want to use "Insert" instead of "Append". Then you can specify that all your tweens start at 0 (or whenever you like)

    Code (CSharp):
    1. seq.Insert(0f,card.transform.DOLocalMove(cardData.FinalPosition, duration));
     
    tsibiski likes this.
  25. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    394
    Thanks!
     
    flashframe likes this.
  26. Ignacii

    Ignacii

    Joined:
    May 23, 2013
    Posts:
    81
    Would love to see DoTween integrated with Unity's Visual Scripting. Or at least a step-by-step guide to setup everything in a more complicated way. I mean every function of DoTween like DoVirtual etc. not only the basic stuff
     
  27. Oddyseous

    Oddyseous

    Joined:
    Jan 30, 2020
    Posts:
    5
    Installed Dotween for the first time today but ran into some issues. I already re-imported and re-started unity. Yes I did the setup, no I didn't have a previous version. Using Unity 2021.3.9f1 Editor, I have 18 errors, most are similar. If anyone could point me in the right direction on these I'd really appreciate it.



     
  28. Oddyseous

    Oddyseous

    Joined:
    Jan 30, 2020
    Posts:
    5
    Demigrant responded via Twitter. Turns out in Setup I had Dotween Performant Outlined, which I guess is something separate I don't have so it was causing all these errors. I just had to run setup again and uncheck it. Thanks for the help!
     
  29. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    69
    Have a button click handler that calls this code to run a canvas fade, then do other stuff in the callback.
    Works as expected the first time the code is run, but after that it does nothing.
    It doesn't fade the canvas alpha or fire the callback.
    What am I missing?

    This just shows part of the code in the button click handler:
    Code (CSharp):
    1.                 Tweener t = this.MissionLoadingCanvasGroup.DOFade(1f, this.fadeToBlackTime);
    2.                 t.onComplete = new TweenCallback(this.MissionLoadFadeToBlackCallback);
     
  30. eraab953

    eraab953

    Joined:
    Nov 19, 2018
    Posts:
    4
    Thought I solved this but still running into the same problem...it just happens very randomly. I'm having an issue with using DoTween with Opisive Behaviour Designer. My one enemy has an ability to Dash across the screen, where a there's a warm up Tween (startPositionTween), then Dash(), which is just an AddForce() method. My problem is, sometimes the enemy's velocity stays at zero when the Dash() method is called, and I can't figure out why. I've debug.logged it to know that Dash() is definitely called, just it seems the force isn't being applied? Anyone have any clue what I'm doing wrong? Any help is greatly appreciated!

    Code (CSharp):
    1. using BehaviorDesigner.Runtime.Tasks;
    2. using DG.Tweening;
    3. using UnityEngine;
    4.  
    5. public class EnemyDash : EnemyAction
    6. {
    7.     public bool hasLanded;
    8.     public string animationTriggerName;
    9.     //private Tween dashTween;
    10.     private Tween startPositionTween;
    11.    
    12.     public bool isDashing;
    13.     public float warmUpTime;
    14.     public float dashLength;
    15.     public float dashForce;
    16.     public float dashTaskLength;
    17.    
    18.     private Tween dashTaskTween;
    19.     private bool facingRight;
    20.    
    21.     public float dashTimer;
    22.     public float dashTime;
    23.    
    24.     public override void OnStart()
    25.     {
    26.         GetInPosition();
    27.     }
    28.    
    29.    private void Dash()
    30.    {
    31.        player.GetComponent<SimpleCameraShake>().ShakeCamera();
    32.        rb.AddForce(new Vector2 (dashForce * transform.localScale.x, 0));
    33.    }
    34.  
    35.    private void GetInPosition()
    36.    {
    37.        animator.SetTrigger(animationTriggerName);
    38.  
    39.        startPositionTween = DOVirtual.DelayedCall(warmUpTime, () =>
    40.        {
    41.            Dash();
    42.        }, false);
    43.      
    44.        // tween for whole task
    45.        dashTaskTween = DOVirtual.DelayedCall(dashTaskLength, () =>
    46.        {
    47.             hasLanded = true;
    48.        }, false);
    49.    }
    50.  
    51.        public override TaskStatus OnUpdate()
    52.     {    
    53.    
    54.         return hasLanded ? TaskStatus.Success : TaskStatus.Running;
    55.     }
    56.    
    57.    public override void OnEnd()
    58.    {
    59.        dashTaskTween?.Kill();
    60.        startPositionTween?.Kill();
    61.        hasLanded = false;
    62.    }
    63.  
    64.  
    65.  
    66. }
    67.  
     
  31. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    Are you modifying / setting the velocity of the rigidbody in any other action? (specifically any action that follows this dash action) Is there a combination of "EnemyActions" that can cancel out the dash force?
     
  32. eraab953

    eraab953

    Joined:
    Nov 19, 2018
    Posts:
    4
    the only other task that is modifying the rigidbody is the EnemyWalk task, but that doesn't affect the velocity, just the position. I don't think anything can cancel it out, I have it rigged where it's always preceded by a Wait and FacePlayer task (which just changes the enemy's local scale based on the position of the player).

    here's the EnemyWalk code:


    Code (CSharp):
    1. using BehaviorDesigner.Runtime.Tasks;
    2. using DG.Tweening;
    3. using UnityEngine;
    4.  
    5. public class EnemyWalk : EnemyAction
    6. {
    7.    
    8.     public float walkSpeed;
    9.     public float distance;
    10.     public float walkCycleLength;
    11.     private Tween walkTween;
    12.     public string animationTriggerName;
    13.     private float walkTimeBeforeAttack;
    14.     public bool finishedWalking;
    15.    
    16.     public bool isWalking;
    17.    
    18.    
    19.    
    20.      public override void OnStart()
    21.     {
    22.         animator.SetBool(animationTriggerName, true);
    23.         walkTimeBeforeAttack = Random.Range(2, 4);
    24.         Walk();
    25.        
    26.     }
    27.    
    28.     private void Walk()
    29.     {
    30.         isWalking = true;
    31.        
    32.         walkTween = DOVirtual.DelayedCall(walkCycleLength, () =>
    33.         {
    34.             isWalking = false;
    35.             finishedWalking = true;
    36.         }, false);
    37.        
    38.     }
    39.    
    40.    
    41.     public override TaskStatus OnUpdate()
    42.     {
    43.        
    44.         if (isWalking)
    45.         {
    46.             rb.position = new Vector2(rb.position.x + (walkSpeed * transform.localScale.x) * Time.deltaTime, rb.position.y);
    47.         }
    48.            
    49.         return finishedWalking ? TaskStatus.Success : TaskStatus.Running;
    50.     }
    51.    
    52.    
    53.      public override void OnEnd()
    54.     {
    55.         walkTween?.Kill();
    56.         animator.SetBool(animationTriggerName, false);
    57.         isWalking = false;
    58.         finishedWalking = false;
    59.     }
    60.  
    61. }
    62.  
     
  33. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    Right, but setting the position of the rigidbody directly is going to interfere with using forces / velocity.

    If I were you, I'd comment out the walking code and see if that makes a difference. Or stick some Debug.Log() in to see what's getting called on the occasions that the velocity doesn't get set.

    There's nothing obviously wrong with your DOTween code.
     
  34. eraab953

    eraab953

    Joined:
    Nov 19, 2018
    Posts:
    4
    I think you're on to something. If I run the FacePlayer -> Wait -> EnemyDash -> Wait -> TurnAround _> Wait Sequence in a loop, there doesn't seem to be a problem. I'll keep messing with it, thank you!
     
  35. eraab953

    eraab953

    Joined:
    Nov 19, 2018
    Posts:
    4
    I think I solved this by switching the game object's Rigidbody to Never Sleep. I know that you're not supposed to do this often, but since this enemy is a boss-type and has a large health bar, I think the rigidbody was falling asleep, somehow?

    appreciate the help!
     
    flashframe likes this.
  36. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51

    Add DORewind() before DOKill() else your animations will start to shift from the original start position.
     
  37. tianlinzhang

    tianlinzhang

    Joined:
    Mar 18, 2021
    Posts:
    8
    Hello! I have bought Dotween Pro recently and have one question regarding path: I have followed the tutorial video on Path, created a cube and add Dotween path and use Shift+Command to create a path, when I run in Play mode, nothing moves, if I restart Unity editor, I can see the cube moves. After restart if I create a new cube and new path, both old cube and new cube do not move, I have to restart the editor again to make both work. Is there anyway to not restart Unity editor to see the new cube move? thanks a lot
     
  38. karolwieczorek9

    karolwieczorek9

    Joined:
    Jun 8, 2015
    Posts:
    4
    Most problably it's because You have DoTween in custom directory. It's worse if it's package like in my case. DoTween in dll have some methods that try to find files and use "Assets" name as reference. I'm trying to make some Ductape script that will fill that assets instead so DoTween will not miss those files or throw errors there.
     
  39. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    585
    calling Complete() while SmoothRewind() is playing causes the tween to complete in the Forward directiong instead of reverse.

    Shouldn't it complete towards the rewind backwards direction?
     
  40. robson_unity208

    robson_unity208

    Joined:
    Jul 14, 2020
    Posts:
    7
    I have an issue with DOTween Path where it just stops working after a while.
    Basically, I have an animation that plays at the end of the level. The DOTween is set to autoplay and I activate the gameobject once I want it to move and restart the tween, since this object persists between levels. Like this:

    Code (CSharp):
    1. GameObjectWithTween.DORestart(true);
    2. GameObjectWithTween.gameObject.SetActive(true);
    It works normally, but sometimes, after several levels, they get stuck on their last position and no longer restart.
    Not sure if this could be related to it being inside of a canvas (I am aware of the warning), it bugs me that it happens seemingly at random.
     
  41. imakemygame

    imakemygame

    Joined:
    Mar 3, 2013
    Posts:
    38
    hi folks,
    does anyone have an idea how to achieve a .DOLookAt and .DOMove at the same time? I try to move my camera to a destination while looking at something. Unfortunately this is not easily working. When I invoke both as mentioned the loookAt Rotation is calculated at the beginning but needs to adjusted while the camera is moving
    Thanks for any help

    Edit:
    Code (CSharp):
    1.        //we do a quick rotation and look at our new target
    2.         _cameraTransform.DOLookAt(_slots[index]._targetLookAt.position, .5f).OnComplete(() =>
    3.         {
    4.             //then we start moving
    5.             _cameraTransform.DOBlendableMoveBy(_slots[index]._targetCameraPos.position - _cameraTransform.position, 1f)
    6.           .SetRelative().SetEase(Ease.Linear)
    7.           //and while moving(OnUpdate) do a LookAt to stay focused on our new target
    8.           .OnUpdate(() =>
    9.           {
    10.               _cameraTransform.LookAt(_slots[index]._targetLookAt.position);
    11.           });
    12.         });
    this is my current code but it is more a workaround since I do a DOLookAt at the beginning, but my aim is to start looking at and moving at the same time.
     
    Last edited: Jan 1, 2023
  42. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    324
    Hello. DORotate seems to always rotate in the same direction. Any way to make it rotate in the other direction?
     
  43. maax511

    maax511

    Joined:
    Jan 21, 2021
    Posts:
    6
    Hi. How do I create custom EaseFunction. I want make animation of throwing one object towards other by parabolic trajectory. I know hoe to do this using Lerp, but it dosen't match with other DOTween animations. Documentation link with example leads me to this forum to a random page.
     
  44. maax511

    maax511

    Joined:
    Jan 21, 2021
    Posts:
    6
    have you set RotateMode to RotateMode.FastBeyond360? If you don't it will try to find shortest way to get the end value.
     
    TiggyFairy likes this.
  45. Nickromancer

    Nickromancer

    Joined:
    Jul 31, 2016
    Posts:
    92
    Help.

    I don't know why my tween sequence will occasionally stop finishing. I don't see any flaw in my code and this is annoying me for quite some time.

    The code below should set the CanvasGroup alpha to invisible at the end. I even added a OnKill callback to ensure it end with transparent (alpha = 0) color. But occasionally it just stuck at some value like 0.1706 instead of 0. The object is not destroyed and the visual is just stuck on the screen with 0.17 alpha making it slightly visible.

    P.S. when I explicitly test it by keep calling it many time continuously. It issue does not happen even once. It just happen in rare occasion during game session. So its quite hard to reproduce.
    The issue also happen on another sequence. But in this case, the object (CanvasGroup) is only controlled by this sequence and so there is no other tween try to modify the same target for a different value.

    Code (CSharp):
    1.  
    2.     public void Play( StageUnitWidget target, float duration, float flashCount)
    3.     {
    4. #if UNITY_EDITOR
    5.         Debug.Log($"Play Radiating Lines... (Duration = {duration}s,  Flashes={flashCount})");
    6. #endif
    7.         KillTween();
    8.  
    9.         if (target != null )
    10.         {
    11.             transform.position = target.centerAtWorldPosition;
    12.             transform.SetLocalZ(0);
    13.         }
    14.  
    15.         mSequence = DOTween.Sequence();
    16.  
    17.         var t = duration / 4f;
    18.  
    19.         for (var i = 0; i < flashCount; i++)
    20.         {
    21.             mSequence.Append(canvasGroup.DOFade(alphaHi, t).SetEase(Ease.OutSine));
    22.  
    23.             mSequence.Append(canvasGroup.DOFade(alphaLow, t).SetEase(Ease.InSine));
    24.         }
    25.  
    26.         if (fadeOutDuration > t * 2)
    27.         {
    28.             mSequence.Append(canvasGroup.DOFade(alphaHi, t).SetEase(Ease.OutSine));
    29.             mSequence.Append(canvasGroup.DOFade(0, fadeOutDuration - t).SetEase(Ease.OutQuad));
    30.         }
    31.         else
    32.         {
    33.             mSequence.Append(canvasGroup.DOFade(0, t).SetEase(Ease.OutQuad));
    34.         }
    35.  
    36.         mSequence.OnKill(()=> { canvasGroup.alpha = 0; });
    37.         mSequence.SetLink(gameObject);
    38.         mSequence.Play();
    39.     }
    40.  
    41.  
    42.     void KillTween()
    43.     {
    44.         if (mSequence != null)
    45.         {
    46.             mSequence.Kill();
    47.             mSequence = null;
    48.         }
    49.  
    50.         canvasGroup.alpha = 0;
    51.     }

    Update:
    It seems to be related to the Recycle setting. I turned it off and the issue seems to be gone. Don't turn it on guys. Its probably bugged.
     
    Last edited: Jan 13, 2023
  46. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    324
    I haven't, thank you. Do you know how I should set them to get the right effect?
     
  47. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    You can specify the RotateMode if you add a 3rd parameter to your tween:

    Code (CSharp):
    1. DORotate(Vector3 to, float duration, RotateMode mode)
    So you want something like:

    Code (CSharp):
    1. myTransform.DoRotate(newRotation, 1f, RotateMode.FastBeyond360);
    You can also use RotateMode.WorldAxisAdd or RotateMode.LocalAxisAdd to control the direction (by using a positive or negative value)
     
    TiggyFairy likes this.
  48. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    324
    Thank you
     
  49. DavidRodMad

    DavidRodMad

    Joined:
    Jan 26, 2015
    Posts:
    10
    Hello, I was trying to set up a simple tween that is played both forwards and backwards, but I ran into an issue.

    After I play it backwards the sequence seems to be set to backwards mode, so I can't use Play to play it anymore.

    But if I use PlayForward, I can't use the "oncomplete" callback on it.

    Is there a way to set it to not be backwards without playing it, or to play it forward while checking on complete?
     
  50. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    658
    I've never had an issue with OnComplete not being called with PlayForward (and likewise OnRewind when using PlayBackward). Can you post some code where they aren't being correctly fired?