BJS UniversalCamera zoom in

Hi there, (didn’t see you moved to a new forum :slight_smile:)

I’m currently building a FPS game with babylon.js (love the engine <3) and sometimes the player has a sniper rifle, and when they scope I would like to:

  1. Have the UniversalCamera zoom in.
  2. Decrease the UniversalCamera’s angularSensibility (pan around slower).
  3. Overlay a recticle image.

Right now I know how to do 2 & 3 but not 1. I’ve looked around, searching for a way for the camera to zoom in but without luck.

I’m wondering if BJS has a function for this, or if not, is there some other way I can achive this?

If any of you guys know how I can achive this please let me know, thanks.

PS. I haven’t posted any code since I think this is a general question, let me know if you want the code though.

1 Like

Hi,

You can set the fov property, for example for having 2X zoom simply divides fov by 2.

see line 28 :
https://www.babylonjs-playground.com/#1A3M5C#44

1 Like

Thanks @sharp! It works a charm :+1:

Hi guys. If you guys or anyone needs a non-FOV, universal-cam POSITIONAL zoom (dolly-in/out)… with working mouse-wheel… here’s my latest: https://playground.babylonjs.com/#6FHKHC#17

This event “wheel data” method CAN be used to smoothly adjust FOV too, of course.

In previous versions, line 25 used event.wheelData to get its ‘delta’. This version uses the newer event.deltaY. This new version also required a greater-than/less-than change in line 36. Party on.

3 Likes

Bro, how do you make it?

I have a HTML recticle image loaded in the background, then I use JS to show and hide it.

Here’s the recticle image if you need it:

2 Likes