# A constant speed rotation finishing with a correct angle.

 0 I am using the following code : ``````void Update() { var oldRotation = transform.rotation; Quaternion newRotation = Quaternion.Euler(0, 0, 90); transform.rotation = Quaternion.Lerp(oldRotation, newRotation, Time.deltaTime ); } `````` A ~= 90 degree rotation around Z is performed, but the rotation speed is more and more slow and at the end my rotation is of almost 90 but not exactly. I need to perform a rotation of exactly 90 with a constant speed. How can i fix my code to perform such a thing? more ▼ asked May 03 '11 at 10:24 PM Sylario 25 ● 7 ● 7 ● 12 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 I find it's best to keep code simple, so you can understand and change it. Step 1 is to make something go from 0 to 90. Step 2 is to rotate that much: ``````var zTilt : float = 0; var degsPerSec : float = 45; // change to whatever speed you want void Update() { // make zTilt slowly get bigger: zTilt = zTilt + Time.deltaTime * degsPerSec; if(zTilt > 90) zTilt = 90; transform.rotation = Quaternion.Euler(0, 0, zTilt); } `````` That particular use of Lerp is for exactly what you wrote -- more fast than slow down and never quite get there. It's good for going to a moving target. more ▼ answered May 03 '11 at 11:10 PM Owen Reynolds 11.2k ● 1 ● 7 ● 45 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 See the Rotation function here. more ▼ answered May 03 '11 at 11:44 PM Eric5h5 80.1k ● 41 ● 132 ● 519 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: