Fight Game Combo

I am making a character that will punch in a combo when the space bar is pressed rapidly three times…how do i do this in blender game engine?


This is how i would do it:

First link a python script to the space keyboard sensor.

In this script:
When the sensor is positive, store the current time somewhere.
You can get the current time with clock()
Use for example 3 property of your object: 3 float : time1, time2, time3

Then you have to check the difference of time3 and time1, if it is lower than your ‘combo time limit’ you got a combo.
So just change a property somewhere or activate an actuator to signal the combo is on.

I hope i’ve been understandable. I assume you know python. I don’t have the time to do it now, but if you want details, you can ask for.


i do somewhat understand…but have no clue how to enter it all into python text editor and logic bricks…

ok here it is:

Add a keyboard sensor called kbspace to your object

link it to a python controller
you need 4 properties:
int called current
float called time1
float called time2
float called time3

use the debug display to see how it works

use the following script:

from time import *

cont = GameLogic.getCurrentController()
own = cont.getOwner()

combodetected = 0
#in sec. max time to get a combo
combolimit = 0.5

#you have a keyboard sensor call kbspace
sensor = cont.getSensor(“kbspace”)

if sensor.isPositive():
_#the time will be store in time1 then time2
_#then time3 then time1 …(cycle)
_own.current = own.current +1
_if own.current%3 == 0:
__own.time1 = clock()
__if own.time1-own.time2<combolimit:
___combodetected = 1
_elif own.current%3 == 1:
__own.time2 = clock()
__if own.time2-own.time3<combolimit:
___combodetected = 1
__own.time3 = clock()
__if own.time3-own.time1<combolimit:
___combodetected = 1
_if combodetected == 1:
__print “combo detected”
__#add these line if you don’t want
__#a second combo to be detected when the key is pressed a fourth time (within the combo time limit)
__#own.time1 = 0
__#own.time2 = 0
__#own.time3 = 0

I hope you will get it to work!

oups the tabs were gone
i replaced a tab with a _

awesome! thank you very much!

just two questions…what does the %3 added to own.current do? could it be done that if i add combo detected=1, then 2, then 3, for each combo time limit so that each time the button is pressed, the given IPO is played?
thanks again, that cleared up a lot with me.

not that i know any python, but in c, the % is called modulus. it returns the remainder after division.

You’re just right 2extreme, same in python.
Terence1986: if you have installed python, you have a python doc with.
You can get information about %, clock(), tutorial etc (it is just not related to blender)

The %3 helps me doing a cycle with time1,time2,time3 : so that after i’ve written the time in time3 i can start again with time1

I could have written the script this way:
_own.current = (own.current+1)%3
and then remove other %3:
_if own.current == 0: …

Now current will be 0,1,2,0,1,2…
While it was 0,1,2,3,4,5,6… before
note:it is a lit bit more efficient.

I’m not sure what you you exactly mean, but this might help:

link 2 IPO actuators and add in the script:

act = cont.getActuator(“firstIPOname”)
act1 = cont.getActuator(“secIPOname”)

supercombolimit = 0.2

__if own.time1-own.time2<combolimit:
___combodetected = 1
__if own.time1-own.time2<supercombolimit:
___combodetected = 2
__elif own.time1-own.time2<combolimit:
___combodetected = 1
(3 times)

at the end change:
_if combodetected == 1:
__print “combo detected”
_if combodetected == 2:
__print “Supercombo about to be launched”
_elif combodetected == 1:
__print “combo about to be launched”

I hope this is what you wanted.

it is…thank you and merry christmas!