Playing Animations with Game Keys in BGE

So unrelated to the last question I asked…

I’ve been trying to simplify my cluttered logic brick mess by simply converting the walking functions to python scripts. I’ve encountered an issue. I’ve refrained from using the sensors in the logic bricks and instead use Game Keys(bge.events). I’ve got the motion covered but it won’t play any animations.

Code

import bge

def main():

cont = bge.logic.getCurrentController()
owner = cont.owner

keyboard = bge.logic.keyboard
mouse = bge.logic.mouse
scene = bge.logic.getCurrentScene()
armature = scene.objects[‘Player.Rig’]

#move up down, turn left right

if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DOWNARROWKEY]:
owner.applyMovement((0,-.2, 0), True)
armature.playAction(“PlayerWalking”, 1, 30, 0, 2, BLEND, PLAYTYPE, LYRWGHT, IPO_FLG, SPEED, BLENDTYPE)

if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.RIGHTARROWKEY]:
owner.applyMovement((0, 0, .05), True)

if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.LEFTARROWKEY]:
owner.applyMovement((0, 0, -.05), True)

main()

armature.playAction("PlayerWalking", 1, 30, 0, 2, BLEND, PLAYTYPE, LYRWGHT, IPO_FLG, SPEED, BLENDTYPE)

After ‘2’ nothing is defined, either remove it or define the other types.

again look into console to see the errors.

Also next time could you post your code in code tags? (advanced editor # symbol) or simply use code instead of the quote text.

Oh, wow. Aren’t you just a problem solver? That fixed it, but the animation isn’t looping but I’ll fix it.

Just reading over your code, not hard to find to be honest.

Just look at the previous examples we have given you, you should be able to fix it yourself indeed :slight_smile:

Well thanks to you, I learned some coding. I learned how to play animations with game keys. I also did do some research.

Also, how do you fix this annoying error?


just remove all spaces/tabs before that line and above/below and re tab them, should do it.

Okay, I’m not as smart as I thought I would be…

So on the last script you started for me, I’m trying to add factors that would make the player walk slower. I’ve got the movement covered but what about the animations?

How do you make animations speed change?

i did not make a script for you Daedalus_MDW did that, i just helped you with your errors.

anyway, i am not sure if that is possible, atleast i have never used/tried it.
best is to make a new topic for it, and hope for the best.

or simply make 2 animations, one walking and 1 running.

I’m fairly sure you should just be able to change that “SPEED” variable…

Did that, it didn’t work for some reason…

Alright, then. I’ll do so…

Also, it is possible. I have to change the SPEED variable. i’m talking about the animation speed, not the movement. I’ve got that covered.