Camera FOV change with code

Is it possible to change camera FOV with code?
I’m trying to make it where if you scope in it zooms and lowers field of view

Yes, it is, here is how I handle zooming inside the update method:

CameraMovement.prototype.handleTargeting = function(dt){

    // --- zooming
    this.targetFov = this.playerMovement.targeting ? this.zoomFov : this.normalFov;
    this.currentFov = pc.math.lerp(this.currentFov, this.targetFov, this.zoomSpeed * dt); = this.currentFov;

Note: example code, don’t copy/paste directly!


Hey, I have just tried this. And in runtime I don’t see any change in my view.
Do I need some refresh or something? THanks in advance. = 100;

Where are you running that code?

It should be on a script attached to your camera.

It is on that entity. Funny thing is
when I console.log it before I assign it say it is undefined. is undefined. hmmm

My bad.

in my code was entitty. So I had to = 100

instead = 100

Sorry for the confusion. Thanks for the help!

1 Like