- Home /
Issue with Lerping Scale - Not another "what is T" question
Hi guys.
protected override IEnumerator IPlayForward()
{
_currentDuration = 0;
while (_currentDuration < duration || duration < 0)
{
_t.localScale = Vector3.Lerp(_t.localScale, desiredScale, _currentDuration / duration);
yield return StartCoroutine(WaitAndIncrement_IEnumerator(Time.deltaTime));
}
}
currentDuration is a value that is being incremented by the Coroutine "WaitAndIncrement_IEnumerator."
In a simple Debug.Log() it shows that the value is lerping correctly, but the scale is going way too fast. It finishes roughly halfway to 3/4 of way through.
Local Scale for my object is 1,1,1 and the desired scale is 2,2,2.
Any help is greatly appreciated!
*With a 2 second duration, the scale jumps from 1 to 1.9 within the first second, and takes another second to finish the scale
Answer by robertbu · Mar 28, 2014 at 03:07 AM
Your problem is in your Lerp() call. When using Lerp() the way you are using it here, you want the first parameter of the Lerp() to be the starting scale. You don't want to use the current scale. The code would be something like:
protected override IEnumerator IPlayForward()
{
_currentDuration = 0;
Vector3 startScale = _t.localScale;
while (_currentDuration < duration || duration < 0)
{
_t.localScale = Vector3.Lerp(startScale, desiredScale, _currentDuration / duration);
yield return StartCoroutine(WaitAndIncrement_IEnumerator(Time.deltaTime));
}
}
That was it, thanks!
protected override IEnumerator IPlayForward()
{
_currentDuration = 0;
Vector3 currScale = _t.localScale;
while (_currentDuration < duration || duration < 0)
{
_t.localScale = Vector3.Lerp(currScale, desiredScale, _currentDuration / duration);
yield return StartCoroutine(WaitAndIncrement_IEnumerator(Time.deltaTime));
}
}
Your answer
Follow this Question
Related Questions
uGUI keep position and size of GUI elements when anchors change 3 Answers
Saving default transform of an object c# 1 Answer
Scale UI element On One Side 0 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer