Animation Freeze

Hello All,

I am having problems with my animation and keyboard input.

I will briefly explain the details-- I have the following code to move forward in my update method:

       
if (KeyInput.get().isKeyDown(KeyInput.KEY_W))
        {           
           walkForward();
           setRun();
        }



I call the the walkForward() method to actually transform the character to its new position. setRun() sets the characters animations qualities. The problem is that when I press a key the model is being transform like it is supposed to but the animation becomes frozen when the model is being moved. Only when I release the key does the animation continue. How can I resolve this?

   
public void setRun()
    {
        playerSpeed = .075f;
        playerAnimationControl.setRepeatType(JointController.RT_WRAP);
        playerAnimationControl.setActive(true);
        playerAnimationControl.setTimes(16, 26);
        playerAnimationControl.setSpeed(.5f);        
    }



   
public void walkForward()
    {
        Vector3f tempVa = new Vector3f();
        Vector3f loc = player.getLocalTranslation();
        loc.subtractLocal(player.getLocalRotation().getRotationColumn(2, tempVa)
                .multLocal(playerSpeed));
        player.setLocalTranslation(loc);
     }



I have attached a video to show exactly what I mean. I would like to apologize in advance for the horrible quality of the video. :D

Video: http://www.youtube.com/watch?v=UcV7Z5mcfHU

LOL thats funny. I didn't look into any source, but perhaps setting the PlayerAnimationControl.setTimes(16, 26) every time might reset the animation. Try something like this:


public void setRun()
    {
        if(!playerAnimationControl.isActive()) {

          playerAnimationControl.setActive(true);

          playerSpeed = .075f;
          playerAnimationControl.setRepeatType(JointController.RT_WRAP);
          playerAnimationControl.setTimes(16, 26);
          playerAnimationControl.setSpeed(.5f);
       }
    }

nymon said:

LOL thats funny. I didn't look into any source, but perhaps setting the PlayerAnimationControl.setTimes(16, 26) every time might reset the animation. Try something like this:


public void setRun()
    {
        if(!playerAnimationControl.isActive()) {

          playerAnimationControl.setActive(true);

          playerSpeed = .075f;
          playerAnimationControl.setRepeatType(JointController.RT_WRAP);
          playerAnimationControl.setTimes(16, 26);
          playerAnimationControl.setSpeed(.5f);
       }
    }




Now my character just idols. It doesn't move or animate. XD

I think that I had this same problem when I first was implementing model movement with animations.  However, I don't see anything wrong in nymon's solution and I don't recall having to do anything really special for it other than stop/start the animation based on if the model was moving or not.  I'm sure that the original problem is due to resetting the animation each time setRun() is called.  I'll take a look at my code when I get home and see if I find anything different than the solution already provided.

Okay, so this is how I built my animation/movment update stuff (jME 1.x) using ThirdPersonHandler:



   private void buildInput(){
      System.out.print("buildInput()n");

      input = new PlayerHandler(player, properties.getRenderer());

   }




   private void updatePlayerAnim(){



      if (KeyBindingManager.getKeyBindingManager().isValidCommand("forward", true) ||
            KeyBindingManager.getKeyBindingManager().isValidCommand("backward", true) ||
            KeyBindingManager.getKeyBindingManager().isValidCommand("turnRight", true) ||
            KeyBindingManager.getKeyBindingManager().isValidCommand("turnLeft", true)) {
         if (!playerMoving){
            ((JointController) player.getController(0)).setTimes(1, 25);
            player.getController(0).setRepeatType(Controller.RT_WRAP);
            player.getController(0).setSpeed(3f);
            player.getController(0).setActive(true);
            System.out.println("anim_2");
            playerMoving = true;
            animMoving = false;
         }
      } else {
         if (!animMoving){
            ((JointController) player.getController(0)).setTimes(26, 26);
            player.getController(0).setRepeatType(Controller.RT_CLAMP);
            player.getController(0).setSpeed(1.8f);
            player.getController(0).setActive(true);
            playerMoving = false;
         }
      }
   }



I think that you should be able to adapt the code to work with your input keys being read in your update loop.

Problem solved!

Thanks nymon and ashtonv!  :smiley: