Quantcast
Channel: Questions in topic: "interpolate"
Viewing all articles
Browse latest Browse all 93

How to change a value over specified time?

$
0
0
So I have recently been wondering about how I could change a value (basically Lerp it) over a specific, predictable, amount of time... The only way I have been able to successfully do this currently is by using itweens [valueTo][1] method... Not exactly ideal IMO. For one it requires itween and for another it also requires the use of a callback method. I looked through the unity documentation and [Mathf.SmoothStep][2] looks basically what I was looking for!!! Unfortunately I can't seem to get it to work! As I read the documentation I feed it the from value, the to value, and a time measurement and it will interpolate the values. I've tried implementing this a few different ways now. I'm not on the machine with that code on it but I can mock up what I've tried really quickly!!! I've tried to implement it like a Lerp, but that won't work... IEnumerator smoothSteppin () { float timer = 10f; while (timer >= 0) { value = Mathf.SmoothStep(from, to, timer); timer -= Timer.deltaTime; yield return null; } } I've tried to just wait for it to complete. IEnumerator smoothSteppin () { float timer = 10f; value = Mathf.SmoothStep(from, to, timer); yield return new WaitForSeconds(timer); } However in all these cases it seems to just JUMP to it's upper limit. How am I supposed to use this? More importantly how can I most cleanly accomplish my goal (moving a float to a specified value over a predictable time) using only built in unity functions? Thanks a lot for the help! [1]: http://itween.pixelplacement.com/documentation.php [2]: http://docs.unity3d.com/Documentation/ScriptReference/Mathf.SmoothStep.html

Viewing all articles
Browse latest Browse all 93

Trending Articles



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