[Solved] Triggering sound for specific Animation keyframes

Hi Everyone.

I am working on a walk able character and for now I have two actions: idle and walk.
the walk action is a full walk cycle set, with 24 key frames.

I was wondering how can I play a step sound exactly on the key frame where one of the legs touch the ground, and trigger a slightly different step sound when the other leg does it.

The only way that imaged to this is to split the walk action into two different actions: one for the left leg step and other for the right leg. Thus, when one action is over, play a sound and trigger the next animation. However, I’m not sure how to implement this solution for a continuous walk, when the player holds the walk button.

Any ideas or examples about this?


Hi @gsjunior, welcome to the JME community :slightly_smiling_face:

I suppose you are using the new animation system (com.jme3.anim package).

You can do something like this

             sequence(delay(t), callMethod("playStepSound"), delay(t), callMethod("playStepSound"))


Hi @Ali_RS , thanks a lot for your answer.

It made me understand how to use Tweens.

I only changed slightly, because using parallel, it was hard to guess the exactly delay time.
Instead, I used sequence, with the walk cycle split into two steps

Tween fullCycleTween = Tweens.sequence(Tweens.callMethod(this,"playStep2"),walk_l,Tweens.callMethod(this,"playStep1"), walk_r, Tweens.callMethod(this,"playStep2"));
        Action walkCycle = playerAnimComposer.actionSequence("walkCycle", fullCycleTween);```

You’re welcome. Glad you solved it. :slightly_smiling_face:

1 Like