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.entity.camera.fov = this.currentFov;
Note: example code, don’t copy/paste directly!
2 Likes
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.
this.entity.camera.fov = 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.
this.entity.camera.fov is undefined. hmmm
My bad.
in my code this.camera was entitty. So I had to
this.camera.camera.fov = 100
instead
this.camera.fov = 100
Sorry for the confusion. Thanks for the help!
1 Like