I wanted to achieve slow changes in camera perspective

hai brother, How to change the camera foV =20 to foV =50 slowly? I wanted to achieve slow changes in camera perspective.

Hi @11128,

You can use the lerp mathod:

https://developer.playcanvas.com/api/pc.math.html#lerp

Get a current and target value, and in your script update(dt) method slowly get them to converge:

// --- in your script initialize methd
this.currentFov = this.entity.camera.fov;
this.targetFov = this.currentFov;
this.zoomSpeed = 10;

// --- in your script update method
this.currentFov = pc.math.lerp(this.currentFov, this.targetFov, this.zoomSpeed * dt);
this.entity.camera.fov = this.currentFov;

Each time you change the target fov (this.targetFov) the camera will update with an animation.

1 Like