# Best rotation function to use

What would be the best rotation function (Quaternion.Lerp, Transform.Rotate…) to rotate an object around it’s center axis. The rotation needs to be smooth, there needs to be an option to set the speed, and most important of all, for example if I want it to rotate from 0 degrees to -225 degrees, I don’t want the object to choose the shortest rotation and rotate 135 degrees counterclockwise, but I need it to rotate 225 degrees clockwise until it reaches -220 degrees.

I’m a bit lost with all the functions Unity offers and it would be awesome if some of you guys could help me out!

You have a few options.

1. Multiply the rotation by the specific quaternion. It would be really efficient in most cases, but would require you to do it in fixed update.

private Quaternion _rotation;
public float speed;
private float _speed;
public Quaternion rotation {
get {
if (_speed != speed) {
_speed = speed;
_rotation = Quaternion.Euler (0, speed * Time.fixedDeltaTime, 0);
}
return _rotation;
}
}

`````` void FixedUpdate () {
transform.rotation = transform.rotation * rotation;
}
``````

Or if you want to do it in Update, then you will need to call Quaternion.Euler every frame (which is not that good. You will only need speed variable. That is it.

``````void Update () {
transform.rotation = transform.rotation * Quaternion.Euler(0, speed * Time.deltaTime, 0);
}
``````

Or you can use Quaternion.LerpUnclamped. It is really cool. The code would look like this:

``````	private Quaternion _rotation;
public float rot;
private float _rot;
private Quaternion startRotation;
private float startTime;
public Quaternion rotation {
get {
return _rotation;
}
}

void Update () {

if (_rot != rot) {
startTime = Time.time;
_rot = rot;
startRotation = transform.rotation;
_rotation = Quaternion.Euler (0, transform.rotation.eulerAngles.y + rot / 3f, 0);
}

if (Time.time - startTime <= 1f)
transform.rotation = Quaternion.LerpUnclamped (startRotation, rotation, (Time.time - startTime) * 3f);
}
``````

Sure you will need to change it. What it does, is when the target rotation changes, it creates a rotation Quaternion of the target rotation and divides the y target rotation by 3 so no the closes path is chosen.

Actually, other than these things (not even sure about the last one), Transform.rotate would work the best and simplest.