0
\$\begingroup\$

I have an image with a fill amount component controlled by a Mathf Lerp. The problem is, the time for completion of the Mathf Lerp function decreases more than expected when the timescale increases.

When the timescale is equal to 2 the function should take half the time to complete but it takes less than that. Any idea why?

public static float demolishTime = 6.0f

public void OnClickDemolish()
{
    InvokeRepeating("demolishProgress", 0f, 0.1f);
}

void demolishProgress()
{        
    progress += (Time.deltaTime / demolishTime);
    demolishProgressBar[DemolishManager.demolishState].fillAmount = (float)Mathf.Lerp(0, 1, progress);
    if (progress >= 1) demolishCompleted();
}
\$\endgroup\$
1
\$\begingroup\$

When you have a coroutine scheduled with InvokeRepeating, then the repetition frequency is affected by the current timescale. That means the delta-time adjustment in a InvokeRepeating routine is not necessary.

\$\endgroup\$
2
  • \$\begingroup\$ But I did not made any delta-time adjustment, correct? \$\endgroup\$ – ClaudioA Sep 29 '19 at 16:42
  • \$\begingroup\$ @ClaudioA You did: progress += (Time.deltaTime / demolishTime);. Simply change that to 0.1f / demolishTime. The 0.1f is the InvokeRepeating factor. \$\endgroup\$ – Philipp Sep 29 '19 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.