Randomly switch camera and start animation with Python What I have set up:


I have camera_0, camera_1, camera_2, camera_3, and camera_4.
In front of each camera stands a character. (character_0, character_1 and so on)
Each one of the characters has an animation.


What my script should do:


After completing character_0's animation with camera_0, switch randomly to one of the other cameras (1–4).
Start characters_X's animation with camera_X.
After that character's animation ends, again switch randomly to another camera.
Continue in a loop.


The animation should be played in the game engine.

Is that even possible in Blender using Python?
Something to get started:



import random
import bge

cont = bge.logic.getCurrentController()
own = cont.owner

if not own.isPlayingAction():
    # create radom number between 0..3
    x = int(random.uniform(0,4))
    print(x)

    scene = bge.logic.getCurrentScene()
    # set active camera
    cam_name = 'Camera.00'+str(x)
    camera = scene.objects[cam_name]
    scene.active_camera = camera

    # play action
    own.playAction('CubeAction', 0, 20, play_mode=bge.logic.KX_ACTION_MODE_PLAY)


The script above can be used from a Python controller

Note that this plays the Action for the attached object, if the camera views don't overlap this could already work for you.