Counterattack in fighter games

In a fighter type game, is there a particular way to set up a counter attack using logic bricks(or a script, whatever works). Like if the opponent does an action named something like jab1, is there a way to say whenever that attack happens i have something that opposes jab1?

Indeed, you may use the message sensor and actuator. The opponent must send a jab1 message every time it performs the action. The responding one, must receive the message + if the player is at a certain distance (I presume), it performs counter action (which can be done with state actuator).

thanks alot. illl try that out

yes, message sensor’s are useful.
You can do the same with python and globalDict Variables, if you go down the python route, though it’s slightly more complex (but more powerful).

for the player
add an always to this script controller:


import GameLogic
controller = GameLogic.getCurrentController()
owner = controller.owner

#add a counter attack actuator called "counterattack" to the script, make it loop end
counter = controller.actuators["counterattack"]

if GameLogic.globalDict["counter"] == True:
           controller.activate["counter"]


for the enemy
add an always to this script controller:


import GameLogic
 controller = GameLogic.getCurrentController()
 owner = controller.owner
 
 #add the statement here for attacking, and add this to the end
 #e.g a sensor connected to the script called near player

attack = controller.sensors["nearplayer"].positive

if attack:
     GameLogic.globalDict["counter"] = True
if not attack:
     GameLogic.globalDict["counter"] = False