Character Movement

Hello All,



I am trying to get my character to move and animate at the same time. I wrote a simple method to build a KeyInputListener. I have implemented the animation which works quite well. Now, I have no idea on how to move my character without the KeyNodeForwardAction and KeyBindingManager "way" (which is the same way FlagRush handles input and translations) Could someone point me in the right direction?



Here is my buildInput() method:



    private void buildInput()
    {
        input = KeyInput.get();
        input.addListener
        ( new KeyInputListener() {
            public void onKey( char character, int keyCode, boolean pressed )
            {   
               if(pressed == false)
               {
                playerAnimationControl.setRepeatType(JointController.RT_WRAP);
                playerAnimationControl.setActive(true);                  
                playerAnimationControl.setTimes(292, 325);
                playerAnimationControl.setSpeed(.2f);                    
               }
              
               if(character == 'w')
               {
                playerAnimationControl.setRepeatType(JointController.RT_WRAP);
                playerAnimationControl.setActive(true);
                playerAnimationControl.setTimes(16, 26);
                playerAnimationControl.setSpeed(.5f);
                // CODE TO MOVE FORWARD
               }   
  
            }
         }
      );
       
    }

bump.

If your model facing forward is aligned with the z-axis…



    public void walkForward(float tpf) {

        // Moving 1 unit per second
        float distanceToTravel = 1.0f * tpf;

        // Place this movement in a temporary vector
        tempVector.set(0.0f, 0.0f, distanceToTravel);    
  
        // Rotate the vector to face our current rotation
        tempVector = character.getLocalRotation().mult(tempVector);

        // Add the change to the current location
        character.getLocalTranslation().addLocal(tempVector);
    }



I haven't tested it but it should get you started, at least logically.

Also, using the snip I supplied above you would need to implement terrain following logic on your own so you don't walk off a cliff and float happily ever after…



Something like: What is the height of the terrain at new location, and factor that in for the y value.