0
$\begingroup$

I have very little Python knowledge and I'm trying to get a character to play one animation when the A key is pressed, a different animation when the D key is pressed, a different animation when the W key is pressed, and finally a different animation when both the A and D keys are pressed at the same time. I hooked up the appropriate keyboard sensors and action actuators to a python controller and when I test the character, it works with the exception of one problem. Depending on how the keys are pressed in various combinations (not entirely sure which combinations are at fault) the animation will sometimes get stuck as if Blender doesn't recognize that a key has been released and it keeps on playing that keys animation or it will stop playing the animation but will be frozen on a particular frame. I've tried numerous variations of the code, to solve the problem but nothing works and I've tried using just logic bricks without any code, but nothing eliminates the problem from occurring with certain key combinations (like pressing A and W at the same time and then releasing the W key slightly before the A key. This causes the character to get stuck on the A key's animation)

Here is the code I used:

import bge

cont=bge.logic.getCurrentController()

a=cont.sensors['a']

d=cont.sensors['d']

left=cont.actuators['turn_left']

right=cont.actuators['turn_right']

stationary=cont.actuators['stationary']

w=cont.sensors['w']

walk=cont.actuators['walk']

if a.positive and d.status==0:

    cont.activate(left)

else:

    cont.deactivate(left)

if d.positive and a.status==0:

    cont.activate(right)

else:

    cont.deactivate(right)

if a.positive and d.positive:

    cont.activate(stationary)

else:

    cont.deactivate(stationary)

if w.positive:

    cont.activate(walk)

else:

    cont.deactivate(walk)

I've tried everything I can think of but its become a great frustration. Please help!

Here is a screenshot:

problem setup of character animations

$\endgroup$
  • $\begingroup$ @Amir The preferred formatting for keyboard keys is to use <kbd> formatting. E.g. <kbd>A</kbd>. $\endgroup$ – Ray Mairlot Oct 16 '18 at 17:02
0
$\begingroup$

The problem is that the action actuator is broken since 2.62. When you play different actions one after the other at the same object, some animations will not be shown. The bugtracker contains several reports already.

To avoid that problem you can play the animations with python via playAction().

It is not my preferred solution, but as long as the action actuator does not work as expected, it is a solution.

$\endgroup$
  • $\begingroup$ Game engine has died, I wouldn't hold my breath for getting this fixed. developer.blender.org/… $\endgroup$ – Kirbinator May 11 '18 at 17:34
  • $\begingroup$ This is an irrelevant comment. The bug is present since 2.62 (now we have 2.79). Do you really think I expect this will be fixed in future? $\endgroup$ – Monster May 14 '18 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy