目录

Unity-Lerp和InverseLerp函数用处

目录

Unity Lerp和InverseLerp函数用处

https://i-blog.csdnimg.cn/direct/e282eb532c7d4929a03b37f13f4a42d9.png

https://i-blog.csdnimg.cn/direct/a7077a5991284c6a8f3e81eba4b9ccfe.png

我认为最大的用处就是 缓冲刚体移动 !!!它的作用是每次调用都返回一个 a + (b - a) * t的值,所以只要给一个变化的t值,就可以得到一个适中移动速度的刚体,类似下面这种用法,这样刚体就不会因为移动速度过快而无法检测碰撞

targetPosition = Vector3.Lerp(targetPosition, transpos, Time.deltaTime * moveSpeed);

https://i-blog.csdnimg.cn/direct/f68d09f582b74cd6b25f78bb6f45fe8e.png

https://i-blog.csdnimg.cn/direct/05ce811263e849aa85333e21c0a01a98.png

而逆向插值很好的一个用处是,将某值按比例缩小到0-1,比如我有个值现在是100,我设定的范围值是0-200,也就是

Mathf.InverseLerp(0,200,100)

那么它将会返回0.5,如果传入的值超过200则按1算,小于0按0算

附上官方文档~