4

I'm trying to animate Time.timescale using an easing function with DOTween.

Tweening the value itself seems to work:

DG.Tweening.DOTween.To(value => Time.timeScale = value, 1, 0, 0.4f);

But all the SetX() methods mentioned in the documentation are not available on the object this returns and while I found out that I could set the timeScale property, there doesn't seem to be any way to use an easing function for this tween.

What am I missing?

Patrick Klug
  • 14,056
  • 13
  • 71
  • 118

2 Answers2

6

Figured it out:

Unfortunately it seems that all SetX() methods in DOTween are implemented as extension methods. This means that these methods are simply not available if you are trying to use DOTween by specifying the full type, rather than including the namespace.

This works:

using DG.Tweening;
///
DOTween.To(()=> Time.timeScale, x=> Time.timeScale = x, 2, 0.4f).SetEase(Ease.InQuad).SetUpdate(true);

This does not work:

DG.Tweening.DOTween.To(()=> Time.timeScale, x=> Time.timeScale = x, 2, 0.4f).SetEase(DG.Tweening.Ease.InQuad).SetUpdate(true);
Patrick Klug
  • 14,056
  • 13
  • 71
  • 118
  • It seems to work without the DOTween on your SetEase chain method, i,e. : DG.Tweening.DOTween.To(()=> Time.timeScale, x=> Time.timeScale = x, 2, 0.4f).SetEase(DG.Tweening.Ease.InQuad).SetUpdate(true); – Jayson Ash Sep 23 '15 at 01:27
  • sorry, was a minor mistake in my example (corrected). the fact remains that you have to use 'using DG.Tweening' for the SetEase() and SetUpdate() methods to be valid calls. That's because they are implemented as extension methods. – Patrick Klug Sep 23 '15 at 01:48
1

It looks to me like you're wanting to pause execution by slowing time down gradually rather than instantaneously stopping it and you want to use an easing method.

To set an ease on a DOTween just add on the Ease method call via chaining like this:

DG.Tweening.DOTween.To(value => Time.timeScale = value, 1, 0, 0.4f).SetEase(Ease.InCubic));

Chain more methods together like this, this runs Debug.Log on every Update call:

DG.Tweening.DOTween.To(value => Time.timeScale = value, 1, 0, 0.4f).OnUpdate(()=>{ Debug.Log(Time.timeScale); }).SetEase(Ease.InCubic);

Running this code shows that Time.timeScale doesn't actually get to zero, probably due to floating point precision errors; however, using the OnUpdate chain method Time.timeScale can be assigned zero once it gets close enough:

DG.Tweening.DOTween.To(value => Time.timeScale = value, 1, 0, 0.4f).OnUpdate(()=>{ if (Time.timeScale < 0.001f) Time.timeScale = 0; }).SetEase(Ease.InCubic);

I hope this helps!

Jayson Ash
  • 709
  • 1
  • 5
  • 8
  • I think I'm missing something because I don't have a .SetEase(), nor a OnUpdate() method available. – Patrick Klug Sep 22 '15 at 08:17
  • That's strange. Check out this link and search the page for "Chained callbacks" (without the quotes): http://dotween.demigiant.com/documentation.php You should have all of those methods at your disposal, OnUpdate, OnComplete, OnStart, etc. – Jayson Ash Sep 22 '15 at 08:38
  • Thanks, for your help. I figured it out. See my own answer: http://stackoverflow.com/a/32727494/10779 - silly mistake to make. – Patrick Klug Sep 22 '15 at 21:47