remove second-order term from kinematic motion

This commit is contained in:
Andrew Meadows 2016-04-18 14:19:44 -07:00
parent 8cbec06616
commit ad045bc439
2 changed files with 6 additions and 3 deletions

View file

@ -947,9 +947,10 @@ bool EntityItem::stepKinematicMotion(float timeElapsed) {
&& glm::length2(linearVelocity) < MIN_KINEMATIC_LINEAR_SPEED_SQUARED) {
linearVelocity = Vectors::ZERO;
} else {
// position's acceleration term uses deltaVelocity rather than raw gravity
// for more accuracy (includes damping effects)
position += timeElapsed * (linearVelocity + 0.5f * deltaVelocity);
// NOTE: we do NOT include the second-order acceleration term (0.5 * a * dt^2)
// when computing the displacement because Bullet also ignores that term. Yes,
// this is an approximation and it works best when dt is small.
position += timeElapsed * linearVelocity;
linearVelocity += deltaVelocity;
}
} else {

View file

@ -309,6 +309,8 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
if (glm::length2(_serverVelocity) > 0.0f) {
_serverVelocity += _serverAcceleration * dt;
_serverVelocity *= powf(1.0f - _body->getLinearDamping(), dt);
// NOTE: we ignore the second-order acceleration term when integrating
// the position forward because Bullet also does this.
_serverPosition += dt * _serverVelocity;
}