Toggling Cameras with Independent Movement

I’m working on a project where two cameras can be toggled to view a different mesh. The two cameras should be independent of each other movement wise. When I rotate camera 1, camera 2 should not move at all, however, when I toggle between cameras they seem to sync on where the last camera was at. Is there a way to ensure this doesn’t happen? To provide more context, if I rotate camera 1 to look at a mesh from a side view, I’d want camera 2 to look from a different angle similar to how in Blender or Unity you could setup various viewports from different angles.

Here is a simple playground where I created a second camera and have a setInterval to swap between them to keep it simple: Babylon.js Playground

Ok I think I figured it out. Maybe someone can point out if there is a better way to do this but i’m detaching control before swapping cameras, then re-attaching afterward. Here is the playground: Babylon.js Playground

Seems that you need to take into account camera target as well?

I set up the target initially, but the main focus was just getting independent controls. In my project I can toggle between two different meshes, each with their own camera. As long as I can move the camera and keep those same transform values unique to each camera when toggling then that’ll work fine. Is there any issue with detaching/attaching controls like shown in the playground?

Seems that the issue was with detaching control, this PG works as it should to - https://playground.babylonjs.com/#8VYPN5#3

1 Like

I think attaching/detaching the controls is the right way to do it.

cc @PolygonalSun to be sure.

1 Like

Yep, that was pretty much what I had, I didn’t save the playground I made my changes in though so thanks for providing it. Thanks everyone for the help!

There’s actually a scene.switchActiveCamera() function

scene.switchActiveCamera(camera)
2 Likes

But I prefer to use an intermediate transition camera

2 Likes

Thanks, I wasn’t aware of that. That seems to be a bit easier to utilize since it doesn’t look like I need to keep toggling the controls on and off. The transition camera is also useful, much appreciated!

Attach/Detach is definitely the way to go. When swapping cameras, I totally recommend using the function that @qq2315137135 pointed out as that will automatically detach/attach.

1 Like