Reputation: 137
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
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