user2497684
user2497684

Reputation: 137

How to slowly rotate spherical shapes using Lerp?

I need to slowly rotate spherical shapes which are placed on waypoints. It needs to rotate slowly. How can I achieve this with Lerp?

The code I currently have:

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

Upvotes: 1

Views: 2731

Answers (1)

Joetjah
Joetjah

Reputation: 6132

Check out how to use Quaternion.Lerp on the wiki-site.

Using that example:

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

Upvotes: 2

Related Questions