Hi everybody, i’m working on a fight game and get stuck in some functions:
_Need to play some actions, like walk and guard, ONLY when the key input is pressed, something like flipper mode in logic bricks, but with python. I’ve tried many codes and aways plays the entire animation.
_Hold the animation (action “Guard”) on certain frame while key is pressed and continue the animation til the end when key is released.
My code so far:
import bge
def charActions():
cont = bge.logic.getCurrentController()
own = cont.owner
keyboard = bge.logic.keyboard
guardOn = True
backKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.AKEY]
frontKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DKEY]
lkickKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.JKEY]
mkickKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.KKEY]
hkickKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.LKEY]
lpunchKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.UKEY]
mpunchKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.IKEY]
hpunchKey = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.OKEY]
if backKey and frontKey:
backKey = bge.logic.KX_INPUT_NONE
frontKey = bge.logic.KX_INPUT_NONE
if backKey and guardOn:
own.playAction('Guard',1,10,layer=0, priority=1, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
if backKey:
own.playAction('WalkBack',1,18,layer=0, priority=5, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif frontKey:
own.playAction('WalkFront',1,18,layer=0, priority=5, blendin=0, play_mode= bge.logic.KX_ACTION_MODE_PLAY)
elif lkickKey:
own.playAction('LKick',1,15,layer=0, priority=4, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif mkickKey:
own.playAction('MKick',1,16,layer=0, priority=3, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif hkickKey:
own.playAction('HKick',1,18,layer=0, priority=1, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif lpunchKey:
own.playAction('LPunch',1,8,layer=0, priority=4, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif mpunchKey:
own.playAction('MPunch',1,17,layer=0, priority=4, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
elif hpunchKey:
own.playAction('HPunch',1,17,layer=0, priority=2, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
else:
own.playAction('Stand',1,44,layer=0, priority=6, blendin=0, play_mode=bge.logic.KX_ACTION_MODE_PLAY)
charActions()