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