How to get camera to follow multiple moving meshes

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

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.

1 Like

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

Find center of root node | Babylon.js Playground (babylonjs.com)
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.

3 Likes

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

1 Like

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

check lines 241, 250

Explanation for this is in my first post of this thread

3 Likes

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

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

1 Like