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

View file

@ -309,6 +309,8 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
if (glm::length2(_serverVelocity) > 0.0f) { if (glm::length2(_serverVelocity) > 0.0f) {
_serverVelocity += _serverAcceleration * dt; _serverVelocity += _serverAcceleration * dt;
_serverVelocity *= powf(1.0f - _body->getLinearDamping(), 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; _serverPosition += dt * _serverVelocity;
} }