Just trying to get my planet to expand and then contract, its expanding properly to the large size then just flashing between the small and large scale.
var bigScale : Vector3 = Vector3(3,3,3); var smallScale : Vector3 = Vector3(1,1,1);
I know its something simple just can't get it to work right.
asked Sep 28 '10 at 08:29 PM
Hi, I believe it is because you are using Time.time in your lerp. Have a look at eric5h5's answer on this unityAnswers page: link It is very informative on this issue. The last paragraph describes why Time.time does not work, the rest has some solutions.
answered Sep 28 '10 at 10:42 PM
Just replace Time.time with Time.deltaTime. I tested the code and it works well, alternating between shrinking and expanding the scale of a sphere.
Here's the code:
On a side note, I also sped it up to 5 instead of 0.5 so you can see the change faster. When set to 0.5 you'll get a very long period of time where the planet seems to expand/shrink VERY slowly. This is because it's waiting to reach exactly smallScale/bigScale.
Instead I would suggest waiting for a smaller number, for example:
Note the if conditions are waiting for a number near the target. This way you'll skip the part where the planet keeps scaling at ~0.00001 per second. Also, I only compared localScale.x, as there's no need to compare the rest since the planet is expanding the same in all axis.