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() #slideNumberDisplay=scene.objects['Text'] 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) return; if nextAction.positive: print(nextAction.key) navigate('next') elif previousAction.positive: print(previousAction.key) navigate('previous')