1
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ Do you want to play the animation in the game engine or do you want to render it as an animation? $\endgroup$
    – stacker
    Commented Dec 18, 2014 at 10:54
  • $\begingroup$ hi. In the end it should run in the game engine (without a "player" though, more like a never ending movie). $\endgroup$
    – Sputi
    Commented Dec 18, 2014 at 15:59

1 Answer 1

2
$\begingroup$

Something to get started:

enter image description here

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.

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you very much! You helped me a lot, however I don't quite understand how the camera switch works. Right now it switches through every camera view before the animation ends. I'd like to have it finish the animation first and only then switch. Could you explain which part of the code does that? Also, after starting from camera.000 only camera 1-3 should be included and it should not go back to camera.000. Thanks again, your help is very much appreciated. $\endgroup$
    – Sputi
    Commented Dec 21, 2014 at 17:16
  • $\begingroup$ @Sputi You're welcome. The scene.active_camera is changed by assigning a camera object previously looked up by name, the name is made by a fixed string "Camera.00" where a suffix is appended. You could google the commands to see what the parameters mean, I hoped to help to get started but it seems that you have to read up a bit more python. This question blender.stackexchange.com/questions/21124/… demonstrates message handling which could be extremly helpful for you when it comes to play different actions. $\endgroup$
    – stacker
    Commented Dec 21, 2014 at 19:10
  • $\begingroup$ Sure, thanks. That i knew:) what I was looking for was the 'CubeAction,0 , 20' part. There I can set the frame length of an animation. Now it works just fine. thank you sir! $\endgroup$
    – Sputi
    Commented Dec 22, 2014 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .