ScriptReference/Mathf.Lerp #557
Replies: 3 comments
-
If you're looking for easing functions to transform your |
Beta Was this translation helpful? Give feedback.
-
Lerp SmoothingIf you do lerp-smoothing (dynamic exponential ease-out with a moving target) like this: void Update(){
value = Mathf.Lerp( value, target, factor ); // this is framerate dependent :(
} The rate of decay will be different for different framerates, which is usually not what you want. Here are some framerate independent variants Method 1 (express in terms of half-life)value = Mathf.Lerp( value, target, 1-Mathf.Pow(2,-Time.deltaTime/h) );
Method 2 (express in terms of remaining fraction per second)value = Mathf.Lerp( value, target, 1-Mathf.Pow( c, Time.deltaTime ) ); Conversion/PortingGiven your existing framerate-dependent setup where Then, Note that both |
Beta Was this translation helpful? Give feedback.
-
Some alternative techniques, for the purposes of smoothing, are: Vector3 velocity;
void Update()
{
var target = new Vector3(0f, 5f, 0f);
float duration = 0.2f;
transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, duration);
// Note: that "duration" is the number of seconds to go from the start to the target position.
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ScriptReference/Mathf.Lerp
https://docs.unity3d.com/ScriptReference/Mathf.Lerp.html
Beta Was this translation helpful? Give feedback.
All reactions