Camera auto radius

Hi,

Is there a function that allows you to target a mesh and automatically change the radius of the camera so that the target takes up the maximum space in the camera view ?

I made this drawing in order to try to make you understand better :

thanks by advance

@VerandaLouis you could try the camera framing behavior Camera Behaviors | Babylon.js Documentation

5 Likes

Hi,

I’ve tried with your solution, wich was a good idea, but it was too complicate to setup with my needs. (i’ve tried something with this PG https://playground.babylonjs.com/#6FBD14#2385 without really success)

I finally found the function zoomOn() form Camera. But now i got 2 problems :

Here is my PG https://playground.babylonjs.com/#6FBD14#2386 where i get these problems

Hi,
Hope you are well. Took a quick at your PG and it looks like you have been messing things around a little :wink: with your KB Info for a start. Next thing is you cannot select a function as a camera setTarget. A mesh is expected. Finally, you have to use target to actually move your camera to a new target. setTarget only sets the target, it doesn’t define it has a NEW (Vector3) target.

Hope this new PG helps. Although, in this crude case scenario, one thing is yet undefined: That’s the direction from which the camera should look at the object and then the transition and eventually ease of the camera.

Edit: Sry, changed the key bindings. Now press H, I or Q to change target.

1 Like

Hi,

Thanks for your reply @mawa, i’ve fixed différente things with this PG.

Now i only have the issue that the box is truncate, i will open a BUG cause i think it is. So i will wait the response befoe closing this QUESTION.

1 Like