Fixed BetterCharacterControl "flickering" when not moving.
Sometimes, when the BetterCharacterControl is not moving, it flickers due it physics being always active. The reason for it being always active is that on the prePhysicsTick method it always set the rigidBody's linear velocity (and the method PhysicsRigidBody.setLinearVelocity(Vector3f) reactivates the physics each time is called). The fix consist on just comparing if the current velocity and the setting one aren't the same and, thus, not setting it (using ZERO_TOLERANCE instead 0 to best results).
This commit is contained in:
parent
b006204c0f
commit
abdd739437
@ -171,6 +171,8 @@ public class BetterCharacterControl extends AbstractPhysicsControl implements Ph
|
|||||||
}
|
}
|
||||||
TempVars vars = TempVars.get();
|
TempVars vars = TempVars.get();
|
||||||
|
|
||||||
|
Vector3f currentVelocity = vars.vect2.set(velocity);
|
||||||
|
|
||||||
// dampen existing x/z forces
|
// dampen existing x/z forces
|
||||||
float existingLeftVelocity = velocity.dot(localLeft);
|
float existingLeftVelocity = velocity.dot(localLeft);
|
||||||
float existingForwardVelocity = velocity.dot(localForward);
|
float existingForwardVelocity = velocity.dot(localForward);
|
||||||
@ -194,7 +196,7 @@ public class BetterCharacterControl extends AbstractPhysicsControl implements Ph
|
|||||||
//add resulting vector to existing velocity
|
//add resulting vector to existing velocity
|
||||||
velocity.addLocal(localWalkDirection);
|
velocity.addLocal(localWalkDirection);
|
||||||
}
|
}
|
||||||
rigidBody.setLinearVelocity(velocity);
|
if(currentVelocity.distance(velocity) > FastMath.ZERO_TOLERANCE) rigidBody.setLinearVelocity(velocity);
|
||||||
if (jump) {
|
if (jump) {
|
||||||
//TODO: precalculate jump force
|
//TODO: precalculate jump force
|
||||||
Vector3f rotatedJumpForce = vars.vect1;
|
Vector3f rotatedJumpForce = vars.vect1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user