2013-06-26 34 views
1

我需要慢慢旋轉放置在航點上的球形形狀。它需要緩慢旋轉。我怎樣才能用Lerp做到這一點?如何使用Lerp緩慢旋轉球形?

的代碼我目前有:

if(!isWayPoint5) 
{ 
    //here i"m using turn by using rotate but i needed rotate 
    //slowly is same as turns train in track. 
    transform.Rotate(0,0,25); 
    isWayPoint5 = true; 
} 

回答

2

退房如何使用Quaternion.Lerp上the wiki-site.

使用例如:

public Transform from = this.transform; 
public Transform to = this.transform.Rotate(0,0,25); 
public float speed = 0.1F; //You can change how fast it goes here 
void Update() { 
    transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed); 
} 
+0

你可能想'Time.deltaTime'在在那裏,我懷疑...... –

+0

@DanPuzey'deltaTime'是完成最後一幀的時間,'time'是遊戲開始以來的時間。每次你的遊戲運行時,「時間」會變得更高,而「deltaTime」的時間根據你的fps而變化。 – Joetjah

+0

有關於https://stackoverflow.com/a/37588536/218152的詳細說明 – SwiftArchitect