UPBGE 0.3.0 Control Character Animations with speed

Hello all,
I am using UPBGE 0.3.0 to make a game. I’m using a USB joystick to control the game. Though I’ve tried many things, I can’t seem to make the character’s walk cycle animation change as the character’s speed increases and decreases. In UPBGE 0.2.5 (Blender 2.79), I was able to use the following script, but can’t get it to work in 0.3.0. I assume it’s because I’m using bge.types.KX_GameObject.applyMovement for the character’s motion. Is there a way for me to get this working?

import bge

def set_frame(cont):
own = cont.owner
if ‘delay’ not in own:
own[‘delay’] = 0

current_mag = own.parent.getLinearVelocity(True).magnitude
if current_mag > 10:
    own['frame'] += 2
elif current_mag > 5:
    own['frame'] += 1
elif current_mag > 2.5:
    if own['delay'] == 0:
        own['frame'] += 1
        own['delay'] = 1
    else:
        own['delay'] -= 1
elif current_mag > 1.25:
    if own['delay'] == 0:
        own['frame'] += 1
        own['delay'] = 2
    else:
        own['delay'] -= 1
elif current_mag > 0.675:
    if own['delay'] == 0:
        own['frame'] += 1
        own['delay'] = 3
    else:
        own['delay'] -= 1

if own['frame'] >= 60:
    own['frame'] = 0

.playAction() does have a speed setting, you can adjust this one, but i’m not sure if you need to restart the animation after altering the speed.

Thanks for the reply Cotaks. I do need to loop the animation.

Looking at the 2.79 API, I found KX_ACTION_MODE_LOOP. I’ll try this and see if it works.

yeah you can loop it with python

    # name, start, end, layer, priority, blendin, mode(0=play,1=loop), layerWeight, ipoFlags, speed
    armature.playAction('animation', 15, 1, 0, 0 ,3, 0, 0, 0, 1.0)

@Cholmberg here is a demo I made a while back to showcase property-based animation-speed.
Note: This works in 0.2 or 0.3 versions.

Blend-File.
Dynamic_Animation_Speed.blend (127.9 KB)

Thanks for your reply! I think I’ve got it figured out.