Vector3.Lerp on a localScale

alt text

scale = Vector3(0.1,0,0.1);
aliveArea.transform.localScale += Vector3.Lerp(scale,aliveArea.transform.localScale,Time.deltaTime/100);

I basically trying to increase the objects localScale by the "scale" var's value, I want the object to "smoothly" grow to this size, but this Vector3.Lerp doesn't seemed to smooth ... or have any effect at all.

Any suggestions? Cheers - C

2 Answers

2

Dude, you asked this in your previous question to me.

http://answers.unity3d.com/questions/50677/increasing-an-gamobjects-transform-localscale-by-1-with-ontriggerstay/50680#50680

I forgot! there's some extra rep for me being forgetful :D

–

That link is broken. Here is a working one: http://answers.unity3d.com/questions/56555/Increasing-an-GamObjects-transformlocalScale-by-1-with-OnTriggerStay.html

–

It's because you're incrementing aliveArea rather than assigning to it. Linear interpolation (Lerp) works by returning a value between your start (param 1) and your end (param 2). What you probably meant to do is this:


scale = Vector3(.1,0,.1);
aliveArea.transform.localScale = Vector3.Lerp (aliveArea.Transform.localScale, scale, Time.deltaTime);

This will make aliveArea's localScale move toward scale with a spring-like motion (moves faster the further away it is from the end values).