jme3 animation continuously


I was wondering about how I can make a Spatial changes place + animate at the same time continuously 

for example in a lot of game when the player hold the run button, then the character will run continuously (with animation)  forward

with current inputSystem of jme3 I dont know how I can do it. with analoglistener then chracter will change the place continuously,but the animation will be reset until the very end.

with actionlistener then the player will have to press, release wait until end of animation then again from beginning. otherwise the character will only change place and animate once at beginning then idle.

you have to play with booleans

I have a CharacaterHandler class that have a boolean "moving".

when the command to move is pressed i call a move method on this character handler setting the moving attribute to true.

If moving was previously false i start the walking animation cycle.

When the command is released i call a stopMove method setting the attribute to false, and i stop the walkcyle blending it to idle anim cylce.

 public void move(Vector3f direction, float value) {
    doMove(direction, value);
        if (!moving) {
        moving = true;

    protected void doMove(Vector3f direction, float value) {
        direction = direction.normalize();

    protected void startMove() {
        blendTo(ANIM_WALKCYCLE, 0.5f, LoopMode.Loop);
    public void stopMove() {
        blendTo(ANIM_IDLE, 0.5f, LoopMode.Cycle);
        moving = false;

and in the onAction of the action listener

public void onAction(String name, boolean keyPressed, float tpf) {
  if (name.equals("move") && keypressed) {
       character.move(viewPort.getCamera().getDirection(), tpf);
  if (name.equals("move") && !keypressed) {


Note that the node is a PhysicsCharacterNode that have a very convenient setWalkDirection method that apply a continuous force to the node giving a direction.
to stop the node set this direction to (0,0,0).

thanks Nehon

it works now ^^

–wait mistake, what I wrote is not correct, forget it–

Empire Phoenix said:

--wait mistake, what I wrote is not correct, forget it--

did you write something ? :D