# Automatically update focusDistance when moving camera

**URL:** <https://forum.babylonjs.com/t/automatically-update-focusdistance-when-moving-camera/43460>\
**Category:** Questions\
**Created:** [August 21, 2023, 12:30pm UTC](https://forum.babylonjs.com/t/automatically-update-focusdistance-when-moving-camera/43460 "2023-08-21T12:30:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mantissa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mantissa/32/34482_2.png) [@mantissa](https://forum.babylonjs.com/u/mantissa)\
**Post date:** [August 21, 2023, 12:30pm UTC](https://forum.babylonjs.com/t/automatically-update-focusdistance-when-moving-camera/43460/1 "2023-08-21T12:30:17Z")

</div>

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

Hey everyone,

I’m pretty new to BabylonJS, but loving it so far. Getting stuck on one small thing however.  
As the title suggests I’m trying to dynamically calculate the focusDistance of my camera.  
I’ve found two methods of achieving this:

1. Using a target and calculating the distance between the camera and the target.
2. Using the camera.radius directly to read the distance between the camera and the target.

However, both methods work initially as the scene loads, but when I move (zoom) the camera the value doesn’t updated.  
I feel like I’m missing something simple to force the variable to update.

For anyone interested, here’s the link to the full project being developed: [GitHub - scumstudios/poliwise: Poliwise Webapp](https://github.com/scumstudios/poliwise)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 21, 2023, 5:05pm UTC](https://forum.babylonjs.com/t/automatically-update-focusdistance-when-moving-camera/43460/2 "2023-08-21T17:05:40Z")

</div>

Welcome aboard!

Do you mean that you want the sphere to always remain in focus?

If so, you can proceed as follows:

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

---

<div class="post-metadata">

**Author:** ![mantissa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mantissa/32/34482_2.png) [@mantissa](https://forum.babylonjs.com/u/mantissa)\
**Post date:** [August 22, 2023, 11:30am UTC](https://forum.babylonjs.com/t/automatically-update-focusdistance-when-moving-camera/43460/3 "2023-08-22T11:30:55Z")

</div>

Wow, thanks, that’s exactly what I needed!  
Looks like I need to study the API for the observables a bit. 🙂
