Automatically update focusDistance when moving camera

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

Welcome aboard!

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

If so, you can proceed as follows:


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