Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 348 forks source link

Something I am missing while apply separate Tweens for individual axes using DOMove #576

Closed stanisz93 closed 2 years ago

stanisz93 commented 2 years ago

Hi, I am trying to apply animattion for some object with two separate behaviours for XZ and Y axis, where one of those would have applied different Ease custom curve, it would look something like that:

note: anims is a list of AnimElement structs with following fields:

public struct AnimElement {
      public Transform checkpoint;
      public AnimAxis animAxis;
      public float duration;
      // this is used to apply Join if previous object is the same
      public bool isJoinedWithPrev;  
      public AnimationCurve animCurve;
    }

where animAxis is just an enum: public enum AnimAxis {All, XZ, Y};

      mainSequence = DOTween.Sequence();
      foreach(var anim in anims):
      {
            if(anim .isJoinedWithPrev)
                  mainSequence .Join(GetSpecificTween(player, anim));
            else
                  mainSequence .Append(GetSpecificTween(player, anim));

      }

where GetSpecificTween is applying different Move depends on AnimAxis in each anim:

      Tween GetSpecificTween(Transform player, AnimElement animElement)
      {
            float duration = animElement.duration;
            Vector3 position = animElement.checkpoint.position;
            Tween tween = animElement.animAxis switch      
            {
                  AnimAxis.XZ => DOTween.Sequence()
                                                .Append(player.DOMoveX(position.x, duration))
                                                .Join(player.DOMoveZ(position.z, duration)),
                  AnimAxis.Y => player.DOMoveY(position.y, duration),
                  AnimAxis.All => player.DOMove(position, duration),
            };
            if(animElement.animCurve != null)
                  return tween.SetEase(animElement.animCurve);
            return tween;
      }

So my problem is that I am getting different results when I add (using Join for second one) two element to mainSequence(durationfor both is the same) : 1) Sequence().Append(player.DOMoveX(..., duration = t1)).Append(player.DOMoveZ(..., duration = t1) 2) player.DOMoveY(..., duration = t1) than when I will simply add player.DOMove(..., duration = t1)

I got different results even if SetEase part is turn off

Thanks for help in advance

stanisz93 commented 2 years ago

yh...turns out after openning this issue, the problem was that when I was iteration over anims, I add callback tween with Debug.Log if debug flag in inspector was turn on, which cause second axis of Move to be join to that debug instead of first axis. Sorry