Rotating around self axis by n degrees ??

Hi,

Like in the topic - how to rotate around self axis by a limited angle ? Quaternion.RotateTowards() does not handle this.

I can do endless rotation with transform.Rotate() but cannot find a way to limit this.

Eg.: At start I have a cube rotated by 45 degrees around Z axis. Then in play mode I want to do animated rotation around self Y axis by 90 degrees.

Is it that complicated or am I missing something ?? Please help.

Many thanks.

Try the following :

public float rotationSpeed = 20;

private float angle = 90;

protected void Update()
{
    if ( angle > 0 )
    {
        float a = Mathf.Min( rotationSpeed * Time.deltaTime, angle );
        angle -= a;
        transform.Rotate( 0, a, 0 );
    }
}