If moving

How can i check if i'm moving I have animations that I would like to be active only if moving however when i check velocity [Velocity: 6.0049536E-22 Desired Velocity: 0.0] its odd it never returns back to 0 is thier another way to check it or would it be easiest to create a boolean algorithm in the class that actually moves the character?



public void update(float time) {
      
      if(movement.getOffGround()){moveForward(null);}
      else if(movement.getRotationalAxis().getVelocity()>0.0)
      {   Vector3f direction = new Vector3f();
         movement.getRotationalAxis().getDirection(direction);
              if(direction.getZ()>0)moveForward(null);
         else if(direction.getZ()<0)moveBackward(null);
         else if(direction.getX()>0)strafeLeft(null);
         else if(direction.getX()<0)strafeRight(null);
      }else idle(null);

      System.out.println("Velocity: "+movement.getRotationalAxis().getVelocity());
      System.out.println("Desired Velocity: "+movement.getRotationalAxis().getDesiredVelocity());
   }

hey there,



for me the obvious approach would be to store the worldLocation of a spatial every update() call and compare the last stored to the current worldLocation. From there you can calculate absolute movement and speed.

don't compare with  0 but with Epsilon or another small value.


if (velocity < 0 + FastMath.EPSILON && velocity > 0 - FastMath.EPSILON ) {
  // we are standing still or are verrrryyy slow
}

thx for the replies however both ways aren't working out so great.  btw is the call getVelocity supposed to return a certain velocity while moving but if standing still decrease to 1.4E-45? wouldn't it of been better if it had returned to 0??



Velocity: 1.4E-45
Desired Velocity: 0.0
Velocity: 1.4E-45
Desired Velocity: 0.0
Velocity: 1.4E-45
Desired Velocity: 0.0
Velocity: 1.4E-45
Desired Velocity: 0.0
Velocity: 1.4E-45
Desired Velocity: 0.0
Velocity: 1.4E-45
Desired Velocity: 0.0

i guess if you have gravity objects will always constantly move and push into each other.



Try to set the autorest threshold of the PhysicsSpace, this should put objects to rest if only very little force is moving them.

well if i place bodyNode.rest(); in the update method it only works as I hold down the move key, otherwise the mesh is stuck in air. However the getvelocity method still returns an ever decreasing value



btw i have a physicsNode circling around the characterPhysicsNode that only reacts if its knockedBack but moves when the baseNode Moves. Is it okay to set that to use the method .rest() in the update function for it and .unrest() for the main physics Node?