- Home /
How to Smoothly lerp the scaling
I am doing a block game right now. in the game i have a game object that shows the sprite of the next coming block . the game object is having the size of the screen at first. then i want this to scale down to the size of the block which i want to happen a smooth manner like a smooth animation. I already tried lerp and slerp but didn't got a perfect solution. Please suggest me a method to do this without using animation . Thanking for all ur supports.. :)
Comment
Lerp should work just fine, did you use Time.deltaTime to increment the lerp value? If not it should help to smooth it.
Answer by Pawscal · Apr 27, 2015 at 09:43 PM
Try something like this:
IEnumerator ScaleObject()
{
float scaleDuration = 5; //animation duration in seconds
Vector3 actualScale = transform.localScale; // scale of the object at the begining of the animation
Vector3 targetScale = new Vector3 (0.5f,0.5f,0.5f); // scale of the object at the end of the animation
for(float t = 0; t < 1; t += Time.deltaTime / scaleDuration )
{
transform.localScale = Vector3.Lerp(actualScale ,targetScale ,t);
yield return null;
}
}
Should do the trick