How to adding Lerping in copy rotation of other entity?

Hi everybody! I am looking for the best way to add lerping to a entity that copy the rotation of other with a fast movement

I am using this code now for copy rotation

var CopyRotation = pc.createScript('copyRotation');

CopyRotation.attributes.add('sourceEntity', {type: 'entity'});

// update code called every frame
CopyRotation.prototype.update = function(dt) {

Hi @Luis_Mb,

What you are looking for is slerp(), that is spherical interpolation between two quaternions:

getRotation() returns a quaternion and setRotation() expects one.

1 Like
const quat = new pc.Quat();

update(dt) {
    const current = entity.getRotation();
    const target = target.getRotation();

    // make 0.01 smaller or multiply dt by scalar (> 1.0) for 
    // faster convergence
    quat.slerp(current, target, 1 - Math.pow(0.01, dt);



hello, what iā€™m trying to do is to give a recoil effect to the camera usin slerp. I declared the the targetRotation and currentRotation like this

this.targetRotation = new pc.Quat();
this.currentRotation = new pc.Quat();

Should i have declare them like you did or like this inside the init like this

 this.currentRotation = this.currentRotation.getRotation();
 this.targetRotation= this. targetRotation.getRotation();