- Home /
How do I increase the size of a GameObject when my firstperson character approaches/collides with it?
Hello,
I am attempting to create an effect of vegetation growing as the character collides with it. I want the player to be able to walk into a field and the trees to grow in size as he/she approaches them. Is there a way to do this? Have been struggling to find the appropriate script.
Many thanks in advance,
Tom
because there is probably no script out there capable of doing exactly what your demands are. You should probably start learning program$$anonymous$$g first:
https://unity3d.com/learn/tutorials/topics/scripting/coding-unity-absolute-beginner
Answer by jimmycrazyskills · Dec 18, 2018 at 01:23 PM
Hi mate, you could try modifying the transform.localScale
property of the vegetation.
If you want it to grow over time then you could maybe use the Mathf.Lerp
function, this would allow you to change from a starting value to an end value in a given amount of time.
In Summary:
You can instantly change it's size by writing something similar to the following (this would grow by 10%):
transform.localScale += new Vector3(0.1F, 0.1f, 0.1f);
But if you want a smooth growing/scaling of your vegetation then you could maybe use something similar to below (you would need to create the targetScale & speed variables for yourself in your script)
transform.localScale = Vector3.Lerp (transform.localScale, targetScale, speed * Time.deltaTime);
Hope this helped mate =D
Thanks man, given me a good direction. Thanks man for the speedy and helpful response.