# Camera auto radius

**URL:** <https://forum.babylonjs.com/t/camera-auto-radius/33740>\
**Category:** Questions\
**Created:** [September 7, 2022, 8:32am UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740 "2022-09-07T08:32:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [September 7, 2022, 8:32am UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/1 "2022-09-07T08:32:39Z")

</div>

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 :

 ![1662538559911](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/f/5ffc57e4f7fc19ea724995a0447ad49203977a20.jpeg)

thanks by advance

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [September 7, 2022, 8:40am UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/2 "2022-09-07T08:40:20Z")

</div>

@VerandaLouis you could try the camera framing behavior [Camera Behaviors | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior)

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [September 8, 2022, 3:58pm UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/3 "2022-09-08T15:58:08Z")

</div>

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](https://playground.babylonjs.com/#6FBD14#2385) without really success)

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

- After using zoomOn() (press “Numpad1” or “3”) nothing is show anymore from a certain distance.  

- The zoom truncate the box4 (press “Space”).  

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

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [September 9, 2022, 10:15am UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/4 "2022-09-09T10:15:56Z")

</div>

Hi,  
Hope you are well. Took a quick at your PG and it looks like you have been messing things around a little 😉 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.

> **[Babylon.js Playground](https://playground.babylonjs.com/#6FBD14%232389)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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.

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [September 9, 2022, 3:58pm UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/5 "2022-09-09T15:58:17Z")

</div>

Hi,

Thanks for your reply @mawa, i’ve fixed différente things with [this PG](https://playground.babylonjs.com/#6FBD14#2390).

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.

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [March 8, 2023, 4:39pm UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/6 "2023-03-08T16:39:55Z")

</div>

link to the BUG : [Camera zoomOn()](https://forum.babylonjs.com/t/camera-zoomon/33809)

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [March 9, 2023, 10:17am UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/7 "2023-03-09T10:17:01Z")

</div>

?? Do you mean the bug is still here today? There’s been some fixes done on zoomOn() lately.  
To be honest, I’m not even sure to remember what the later issue was. Can we get a reminder? Thx,

---

<div class="post-metadata">

**Author:** ![VerandaLouis](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/verandalouis/32/19395_2.png) [@VerandaLouis](https://forum.babylonjs.com/u/VerandaLouis)\
**Post date:** [March 9, 2023, 4:25pm UTC](https://forum.babylonjs.com/t/camera-auto-radius/33740/8 "2023-03-09T16:25:07Z")

</div>

1. I’ve put this link because I said that I was going to open a BUG and it was a way to tie the two together so that people who come in don’t have to search for the BUG in question. Sorry for the lack of explanation. 😅

2. As the BUG discussion states: it wasn’t really a BUG, the framework works fine and I wanted to make it work in a different way, so I proposed a feature that remains to be developed.
