I like to know if there is already a better or cleaner way to do a smooth rotation than I do at this moment.

In the update:

```
if (playerMoveDirection !== null) {
this.rotateTime += dt;
this.rotateSpeed = 0.1;
var original_rotation = new pc.Quat();
var final_rotation = new pc.Quat();
original_rotation.copy(this.entity.getRotation());
this.entity.lookAt(playerMoveDirection, this.entity.getPosition().y, playerMoveDirection);
final_rotation.copy(this.entity.getRotation());
this.entity.setRotation(original_rotation);
var new_rotation = this.rotateTowards(original_rotation, final_rotation, this.rotateSpeed);
this.entity.setRotation(new_rotation);
if (this.rotateTime > this.rotateSpeed){
playerMoveDirection = null;
this.rotateTime = 0;
}
}
```

Other needed functions:

```
// Quat functions
// Get the dot product between two quaternions
Player.prototype.dot = function (quat_left, quat_right) {
var dot = quat_left.x * quat_right.x + quat_left.y * quat_right.y +
quat_left.z * quat_right.z + quat_left.w * quat_right.w;
return dot;
};
// Returns the angle in degrees between two rotations /a/ and /b/.
Player.prototype.quatAngle = function (quat_a, quat_b) {
var dot = this.dot(quat_a, quat_b);
if(quat_a.equals(quat_b) )
{
return 0;
}
var rad2Deg = 1 / (Math.PI / 180);
var angle = Math.acos(Math.min(Math.abs(dot), 1)) * 2 * rad2Deg;
return angle;
};
// Rotates a rotation A towards B.
Player.prototype.rotateTowards = function (quat_a, quat_b, percent) {
var angle = this.quatAngle(quat_a, quat_b);
if (angle === 0)
{
return quat_b;
}
return new pc.Quat().slerp(quat_a, quat_b, percent);
};
```