Switch camera issue

Hi!

I have a issue with switching cameras.

I just want to switch between camera1 and camera2.
Thats working nice by setting scene.activeCamera = camera2 for example.
BUT
If i switch to a camera1, than looking around with mouse and than switching again to camera2, the camera is moving around. It seems, that this is the movement of the last camera before switching.
Anyway i want to avoid this issue.

Here is my Playground: Babylon.js Playground

To see the issue:
0) we start with camera1

  1. press “b” (switch to camera2)
  2. please look around a little bit with mouse
  3. press “a” (switch to camera1)

you can toggle between “a” and “b” again and again and if you look around than the camera has this moving issue.

(my camera1 in the script is called “camera”, please dont be irritated)

Please can someone help me to avoid this?
Thank you in advice!

You need to detach the control from the currtent camera so that it does not move when switching to the other camera:

https://playground.babylonjs.com/#R109VJ#1

2 Likes

Thank you Evgeni.
This works in the PG.

Now i see that it works with the default cameras.
I have trouble with this kind of input like in this example:
https://playground.babylonjs.com/#CTCSWQ#1

Here camera.detachControl(); at the end would cause a error “t undefined”.

Any Idea to detach this input?

Ah, i can RemoveByType and then detachControl.
Thanks a lot!

2 Likes

I think I will keep with the default for my scene. It kind of ads some dynamic to my quiet scene.
It’s great to have the answer though and this sure does work :smiley: