# How to get camera to follow multiple moving meshes

**URL:** <https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388>\
**Category:** Questions\
**Created:** [February 29, 2024, 2:26am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388 "2024-02-29T02:26:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![VoxelCubes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/voxelcubes/32/8760_2.png) [@VoxelCubes](https://forum.babylonjs.com/u/VoxelCubes)\
**Post date:** [February 29, 2024, 2:26am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/1 "2024-02-29T02:26:51Z")

</div>

Hi there,

How can I get a camera( **ArcRotateCamera** ) to follow multiple **moving** targets/meshes at once? Example in the video below.

[https://www.youtube.com/watch?v=aLpixrPvlB8](https://www.youtube.com/watch?v=aLpixrPvlB8)

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [February 29, 2024, 8:55am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/2 "2024-02-29T08:55:25Z")

</div>

I would compute the average position of the followed object. Set it as target  
then, compute max distance between that average position and positions of followed object → use it as radius.

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [February 29, 2024, 8:58am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/3 "2024-02-29T08:58:26Z")

</div>

If it’s side scrolling, how about this method?

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

---

<div class="post-metadata">

**Author:** ![xiehangyun](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/xiehangyun/32/30777_2.png) [@xiehangyun](https://forum.babylonjs.com/u/xiehangyun)\
**Post date:** [February 29, 2024, 9:37am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/4 "2024-02-29T09:37:03Z")

</div>

[Find center of root node | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#JVTZTI#8)  
Simply calculate the bounding box of all the mesh collections that need to be traced, and then calculate the target and radius of the camera.

---

<div class="post-metadata">

**Author:** ![VoxelCubes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/voxelcubes/32/8760_2.png) [@VoxelCubes](https://forum.babylonjs.com/u/VoxelCubes)\
**Post date:** [February 29, 2024, 7:42pm UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/5 "2024-02-29T19:42:04Z")

</div>

Awesome guys! Thanks for the input and code snippets.😄 I will give this a try and come back to you.

---

<div class="post-metadata">

**Author:** ![VoxelCubes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/voxelcubes/32/8760_2.png) [@VoxelCubes](https://forum.babylonjs.com/u/VoxelCubes)\
**Post date:** [March 11, 2024, 1:27pm UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/7 "2024-03-11T13:27:13Z")

</div>

Hi guys,

So I have tried but could not get it to work as expected. Would you mind helping me out? Here is a link to the playground I have been playing with. Use keys [A,S,D] & [Z,X,C] to move the meshes in [X,Y,Z] directions, cheers.

[https://playground.babylonjs.com/#LIUX65#11](https://playground.babylonjs.com/#LIUX65#11)

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [March 11, 2024, 1:42pm UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/8 "2024-03-11T13:42:17Z")

</div>

check lines 241, 250

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

Explanation for this is in my first post of this thread

---

<div class="post-metadata">

**Author:** ![VoxelCubes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/voxelcubes/32/8760_2.png) [@VoxelCubes](https://forum.babylonjs.com/u/VoxelCubes)\
**Post date:** [March 11, 2024, 2:22pm UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/9 "2024-03-11T14:22:56Z")

</div>

Many thanks, @Cedric this looks awesome. I will give it a try.

---

<div class="post-metadata">

**Author:** ![VoxelCubes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/voxelcubes/32/8760_2.png) [@VoxelCubes](https://forum.babylonjs.com/u/VoxelCubes)\
**Post date:** [March 12, 2024, 9:05am UTC](https://forum.babylonjs.com/t/how-to-get-camera-to-follow-multiple-moving-meshes/48388/10 "2024-03-12T09:05:20Z")

</div>

Hi @Cedric, it worked like a charm 😃 thanks again!
