Unity Vector3.Lerp()與Vecotr3.MoveTowards()方法區別

<pre name="code" class="html">static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3 
兩個向量之間的線性插值。
按照數字t在from到to之間插值。
1. 當 t <= 0f, = from 。
2. 當 t >= 1f, = to 。
3. 當 0f < t < 1f, = from + (to - from ) * t。
4. 相當於在規定的時間內完成運動。

static function MoveTowards (current : Vector3, target : Vector3, maxDistanceDelta : float) : Vector3 
當前的地點移向目標。
這個函數基本上和Vector3.Lerp相同,而是該函數將確保我們的速度不會超過maxDistanceDelta。maxDistanceDelta的負值從目標推開向量,就是說maxDistanceDelta是正值,當前地點移向目標,如果是負值當前地點將遠離目標。
1. maxDistanceDelta有效取值範圍:maxDistanceDelta <= (target - current).magnitude(向量的長度),當 maxDistanceDelta > (target - current).magnitude 與 maxDistanceDelta = (target - current).magnitude效果一樣。
2. maxDistanceDelta > 0 && maxDistanceDelta <= (target - current).magnitude, 則當前點移向目標target。
3. maxDistanceDelta  < 0 , 則當前點遠離目標target。
4. 相當於按照一定的速度勻速完成運動。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章