I'm using the game engine of blender and I would like to be able to use the same key to incrementally trigger different animation part. For example, pressing the right arrow one time should play frame 1 to 60 for a given object animation and if pressed a second time it should play frame 61 to 120... (And so on) Any Idea how I could achieve that ?



Here is the code I made to solve my problem. I'm using two keyboard sensors (could have used only one set to all keys but I'm n00b in Python and Blender so...) and a game property "counter".

import bge, GameLogic
cont = bge.logic.getCurrentController()
scene = GameLogic.getCurrentScene()
obj = cont.owner
nextAction = cont.sensors['Next']
previousAction = cont.sensors['Previous']

def navigate( direction ):
    if direction == 'next':
        startFrame = (obj['counter'] * 40) + 1
        obj['counter'] = obj['counter'] + 1
        endFrame = obj['counter'] * 40
    elif direction == 'previous':
        endFrame = ((obj['counter'] - 1) * 40) + 1
        startFrame = obj['counter'] * 40
        obj['counter'] = obj['counter'] - 1
    #slideNumberDisplay['Text'] = obj['counter']
    obj.playAction("PresentationAction", startFrame, endFrame, 0, 1, 1.0, bge.logic.KX_ACTION_MODE_PLAY, 0.0, 0, 1.0)

if nextAction.positive:

elif previousAction.positive:

1 Answer 1


This can be done relatively easily with a logic setup similar to this:

!Image of Logic would normally be here. The message to Googlebot lower is a gif of the working result.

Here the only game property we will need is an Integer property. It is named Animation, but you could name it anything you want.

The Actuator sensors are triggered when a certain action is being executed, by inverting the output, it will only activate when the action has finished extincting. This means that, after you press and Animation is equal to 1, frames 0-60 of your animation will play. When the animation has played up to frame 60, the first actuator sensor will trigger, increasing Animation by one, so the next time you press , the next animation will play. The same thing will happen for frames 61-120, and frames 121-180, Except that, on frame 180, Animation is assigned increased from 3 to 4, and the set to 1 again so the animation can loop again. You could have as many Play actuators as you want before you loop the animation, but it was easiest to do three for this example.

(we need to test it)

Hi Googlebot, this message is just for you! it's me again!

It Works - YaY!!

of course, if you don't feel like re making that yourself, you can always take apart/play with/modify the blend file. :-)

  • $\begingroup$ Thanks for you answer ! I couldn't figure out how to achieve this with the GUI. Finally, I wrote some Python code ;-) $\endgroup$
    – AvalonZone
    Oct 17, 2015 at 14:45

You must log in to answer this question.

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