Switching Cameras

Hello,



in my game I need to switch between 2 different Camera mode.

When the game is started I simply use the default flymbycam. The player then can press a key and a new camera is created. That Camera is an own implementation that I found here in the forum (RTSCam).

Creation of the rtsCam looks like that:



[java]

rtsCam = new RTSCam(game.getCamera(), game.getRootNode());

rtsCam.registerWithInput(game.getInputManager());

rtsCam.setCenter(new Vector3f(0, 15f, 0));[/java]



When the user now presses another key I want to switch back to the default flybycam.

So I try to remove the rtsCam:



[java]

game.getInputManager().removeListener(rtsCam);

rtsCam.setEnabled(false);[/java]



Now what works are the controls of the flybycam. I can move normally. But the position of the cam is wrong. It still has the position and lookat of the rtsCam.



Anyone can help me with that?

Thanks in advance.

Just move the cam to another position/direction in one frame, it will seem like a “cam switch” to the user.

But the flybycam has no setposition function or similar.

cam.setLocation(Vector3f) and cam.setRotation(Quaternion) or cam.lookAt(Vector3f, Vector3f).

Yeah, the problem is that it seems to do nothing when I use cam.setLocation when I try to restore the initial view. When I try for example cam.setLocation(new Vector3f(0,0,0)); the camera remains in the rtsCam position.

I guess I need to really remove the rtsCam and reset the default cam or sth like that.

I switch between 2 cams all the time …



[java] if (rtsCam.isEnabled()) {

rtsCam.setEnabled(false);

flyCam.setEnabled(true);

} else {

rtsCam.setEnabled(true);

flyCam.setEnabled(false);

}[/java]

1 Like

Thx for the help, I got it working now. The main problem was that the setEnabled() method of the rtsCam was empty and the update loop of rtsCam was allways running. Thats what happens if you copy&paste :wink: