2

I'm having a problem in creating a yoyo scaling effect with DOTween. I have tried using DoScale, DOScaleShake and DOPunchScale. None seem to work. The rotation that I made works just fine, but I need it to scale as well and that is something I somehow cannot create.

Here is the current code

void Update()
    {
        DOTween.Sequence()
            .Append(crownGlow.transform.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetRelative())
            .Append(crownGlow.transform.DOPunchScale(new Vector3(0.5f, 0.5f, 0.5f), scaleSpeed, 10, 1f));
    }

I even tried it this way and it didn't work

    DOTween.Sequence()
            .Append(crownGlow.transform.DOScale(new Vector3(originalScale.x + 0.5f, originalScale.y + 0.5f, originalScale.z + 0.5f), scaleSpeed).SetEase(Ease.Linear))
            .Append(crownGlow.transform.DOScale(originalScale, scaleSpeed).SetEase(Ease.Linear));

EDIT: With the help of Ryanas, I managed to figure out the solution

void Start()
    {
        originalScale = crownGlow.transform.localScale;
        crownGlow.transform.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental).SetRelative();

        var sequence = DOTween.Sequence()
            .Append(crownGlow.transform.DOScale(new Vector3(originalScale.x + 0.5f, originalScale.y + 0.5f, originalScale.z + 0.5f), scaleSpeed))
            .Append(crownGlow.transform.DOScale(originalScale, scaleSpeed));
            

        sequence.SetLoops(-1, LoopType.Restart);
    }
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
Ivan Jakubi
  • 23
  • 1
  • 1
  • 4

1 Answers1

2

What you're probably looking for is something like this. Sequences shouldn't be created in update every frame because then it means you're applying several sequences on this object every second.

Instead, you want to create the sequence in another function such as Awake or Start. You mentioned that you want it to Yoyo but you need to supply that when you set the number of loops it does. I recommend looking at the documentation for more information: http://dotween.demigiant.com/documentation.php

Here, I've set loop amount to be -1, which means it infinitely loops. You need to add .Join instead of .Append so the two tweens occur at the same time.

void Start()
{
    var sequence = DOTween.Sequence()
           .Append(crownGlow.DOLocalRotate(new Vector3(0, 0, 360), rotationSpeed, RotateMode.FastBeyond360).SetRelative())
           .Join(crownGlow.DOPunchScale(new Vector3(0.5f, 0.5f, 0.5f), scaleSpeed, 10, 1f));
    sequence.SetLoops(-1, LoopType.Yoyo);
}
Ryanas
  • 1,757
  • 3
  • 19
  • 36
  • Ok, this is closer to what I want. I replaced Yoyo with restart, since I don't want the rotation to yoyo, only the scale. The problem now is, when the DOPunchScale is reaching the end, the transform decrease in speed drastically and then stops before starting again. I placed SetEase to Linear to both the rotation and scale. The rotation works fine, but the PunchScale stops before starting again, and I need a constant pulse. – Ivan Jakubi Nov 05 '20 at 08:51
  • Ok! I got what I wanted. It's slightly different then yours but it did help me figure it out. So thanks! (Will put new code in main post) – Ivan Jakubi Nov 05 '20 at 09:01