[SOLVED] Smooth rotation

Okay, I tried again and then I found out that I don’t even need all the extra functions (at least as it seems now). So this is what it looks like now in the update:

Player.prototype.updateDirection = function (dt) {
    if (this.direction !== null) {
        this.rotateTime += dt;
        this.rotateSpeed = 0.05;

        var originalRotation = new pc.Quat();
        var finalRotation = new pc.Quat();

        originalRotation.copy(this.entity.getRotation());
        this.entity.lookAt(this.direction); 
        finalRotation.copy(this.entity.getRotation());
        this.entity.setRotation(originalRotation);

        this.entity.setRotation(new pc.Quat().slerp(originalRotation, finalRotation, this.rotateSpeed));

        if (this.rotateTime > this.rotateSpeed){
            this.direction = null;
            this.rotateTime = 0;
        }
    }
};

When I need to change the rotation of the entity I only have to use something like this:

    this.direction = new pc.Vec3(inputPoint.getPosition().x, this.entity.getPosition().y, inputPoint.getPosition().z);
1 Like