如何使用Lerp缓慢旋转球形?

时间:2013-06-26 07:36:16

标签: c#-4.0 vector unity3d

我需要慢慢旋转放置在航路点上的球形。它需要缓慢旋转。我怎样才能用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;
}

1 个答案:

答案 0 :(得分:2)

查看如何在the wiki-site.

上使用Quaternion.Lerp

使用该示例:

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);
}