Quantcast
Channel: Answers by "Vandarthul"
Viewing all articles
Browse latest Browse all 86

Answer by Vandarthul

$
0
0
Here is a simple script that does what you want by using both Lerp and SmoothDamp. using UnityEngine; public class SmoothDampTest : MonoBehaviour { private Transform myTransform; private Vector3 velocity; public bool useLerp; public Vector3 target; public float smoothTime; public float lerpSpeed; // Use this for initialization void Start() { myTransform = transform; } // Update is called once per frame void Update() { if (useLerp) { myTransform.localScale = Vector3.Lerp(myTransform.localScale, target, Time.deltaTime * lerpSpeed); } else { myTransform.localScale = Vector3.SmoothDamp(myTransform.localScale, target, ref velocity, smoothTime); } } } Attach it to a game object and try both Lerp and SmoothDamp to see if it's what you want. To use lerp: - Select the object that you've attached the script and set these variables on editor: - Use Lerp : true - Target : Set some target( note that if any of this value is 0, object might not be visible) - Lerp Speed: Some value(greater the value, faster the transaction) To use SmoothDamp: - Use Lerp : false - Target : Set some target(note that if any of this value is 0, object might not be visible) - Smooth Time: Some value(lesser the value, faster the transaction, 0 is instant) You can change the values in runtime by the way. This is to understand the behaviour and usage of lerp and smoothdamp. You need to prepare your own implementation(setting a percentage value with your start X value, in your case it's 10). Also please refer to [this link][1] to see the correct usage and details of Lerp. Lerp is not meant to produce a smoothing effect since it is a linear function but passing Time.deltaTime produces faster-start slower-end like effect since the t value is a percentage to target value. [1]: http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html

Viewing all articles
Browse latest Browse all 86

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>