0

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.

David
  • 49,291
  • 38
  • 159
  • 317
sketcherskt
  • 718
  • 1
  • 7
  • 22

2 Answers2

3

The scene actuator allows you to alter the active camera.

scene actuator choices

sambler
  • 55,387
  • 3
  • 59
  • 192
  • 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. – Amir May 08 '18 at 13:10
2

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]

Related Documentation

Strapicarus
  • 1,459
  • 1
  • 9
  • 17