This might have already been asked but how do I switch cameras in blender game engine? What I would like is to play a camera sequence perhaps a panning view around a map and then towards the end switch to a camera linked to my player modal for a third person setup.
2
-
$\begingroup$ Hi sambler, I am here again to bring trouble for you. I have an issue regarding activating cameras. Could you please take a look at my question here? It seems that I am doing everything correctly but the result that I get is so weirdly strange. I need some urgent help and I think you might be able to help me with it. Really appreciate you. $\endgroup$ – Amir May 8 '18 at 13:10
1
$\begingroup$
$\endgroup$
As @sambler answer you can use a scene actuator. Also you can do it with a script.
from bge import logic
locPoint = scene.objects['EmptyPanningEnd'].worldPosition
scene = logic.getCurrentScene()
cam1 = scene.objects['panningCamera']
cam2 = scene.objects['playerCamera']
if locPoint != cam1.worldPosition:
scene.active_camera = cam1
else:
scene.active_camera = cam2
Also if you want to change the camera pressing a key and you have a lot of cameras, add a property and named camera (in each camera).
from bge import logic
own = logic.getCurrentController().owner
scene = logic.getCurrentScene()
camList = [cam for cam in scene.objects if 'camera' in cam.getPropertyNames()]
if logic.keyboard.events[events.CKEY] == logic.KX_INPUT_JUST_ACTIVATED:
change_camera(scene,camList)
def change_camera(scene, camList):
if camList.index(scene.active_camera) < (len(camList) -1):
scene.active_camera = camList[camList.index(scene.active_camera) + 1]
else:
scene.active_camera = camList[0]