MinieLibrary/src/main/java/com/jme3/bullet/control/BetterCharacterControl.java
/**
     * Callback from Bullet, invoked just before the physics is stepped.
     *
     * @param space the space that is about to be stepped (not null)
     * @param timeStep the time per physics step (in seconds, &ge;0)
     */
Callback from Bullet, invoked just before the physics is stepped.
@param space the space that is about to be stepped (not null)
@param timeStep the time per physics step (in seconds, ≥0)
Callback from Bullet invoked just before the physics is stepped . @param space the space that is about to be stepped ( not null ) @param timeStep the time per physics step ( in seconds ≥0 )
@Override
    public void prePhysicsTick(PhysicsSpace space, float timeStep) {
        checkOnGround();
        if (wantToUnDuck && checkCanUnDuck()) {
            setHeightPercent(1);
            wantToUnDuck = false;
            ducked = false;
        }
        TempVars vars = TempVars.get();
        Vector3f currentVelocity = vars.vect2.set(velocity);
        float existingLeftVelocity = velocity.dot(localLeft);
        float existingForwardVelocity = velocity.dot(localForward);
        Vector3f counter = vars.vect1;
        existingLeftVelocity *= physicsDamping;
        existingForwardVelocity *= physicsDamping;
        counter.set(-existingLeftVelocity, 0, -existingForwardVelocity);
        localForwardRotation.multLocal(counter);
        velocity.addLocal(counter);
        float designatedVelocity = walkDirection.length();
        if (designatedVelocity > 0) {
            Vector3f localWalkDirection = vars.vect1;
            localWalkDirection.set(walkDirection).normalizeLocal();
            float existingVelocity = velocity.dot(localWalkDirection);
            float finalVelocity = designatedVelocity - existingVelocity;
            localWalkDirection.multLocal(finalVelocity);
            velocity.addLocal(localWalkDirection);
        }
        if (currentVelocity.distance(velocity) > FastMath.ZERO_TOLERANCE) {
            rigidBody.setLinearVelocity(velocity);
        }
        if (jump) {
            Vector3f rotatedJumpForce = vars.vect1;
            rotatedJumpForce.set(jumpForce);
            rigidBody.applyCentralImpulse(
                    localForwardRotation.multLocal(rotatedJumpForce));
            jump = false;
        }
        vars.release();
    }
@ Override public void prePhysicsTick ( PhysicsSpace space , float timeStep ) { checkOnGround ( ) ; if ( wantToUnDuck && checkCanUnDuck ( ) ) { setHeightPercent ( 1 ) ; wantToUnDuck = false ; ducked = false ; } TempVars vars = TempVars . get ( ) ; Vector3f currentVelocity = vars . vect2 . set ( velocity ) ; float existingLeftVelocity = velocity . dot ( localLeft ) ; float existingForwardVelocity = velocity . dot ( localForward ) ; Vector3f counter = vars . vect1 ; existingLeftVelocity *= physicsDamping ; existingForwardVelocity *= physicsDamping ; counter . set ( - existingLeftVelocity , 0 , - existingForwardVelocity ) ; localForwardRotation . multLocal ( counter ) ; velocity . addLocal ( counter ) ; float designatedVelocity = walkDirection . length ( ) ; if ( designatedVelocity > 0 ) { Vector3f localWalkDirection = vars . vect1 ; localWalkDirection . set ( walkDirection ) . normalizeLocal ( ) ; float existingVelocity = velocity . dot ( localWalkDirection ) ; float finalVelocity = designatedVelocity - existingVelocity ; localWalkDirection . multLocal ( finalVelocity ) ; velocity . addLocal ( localWalkDirection ) ; } if ( currentVelocity . distance ( velocity ) > FastMath . ZERO_TOLERANCE ) { rigidBody . setLinearVelocity ( velocity ) ; } if ( jump ) { Vector3f rotatedJumpForce = vars . vect1 ; rotatedJumpForce . set ( jumpForce ) ; rigidBody . applyCentralImpulse ( localForwardRotation . multLocal ( rotatedJumpForce ) ) ; jump = false ; } vars . release ( ) ; }
Callback from Bullet, invoked just before the physics is stepped.
Callback from Bullet invoked just before the physics is stepped .
// Attenuate any existing X-Z motion. //normalize walkdirection //check for the existing velocity in the desired direction //calculate the final velocity in the desired direction //add resulting vector to existing velocity //TODO: precalculate jump force