Skip to content

Commit

Permalink
UPBGE: Fix angular velocity motion servo with little objects.
Browse files Browse the repository at this point in the history
Previously the force computed in servo control logic brick was multiplied
by the mass. This behaviour is correct because bullet in
btRigidBody::integrateVelocities compute the linear velocity using force / mass.
But the angular velocity doesn't use this formula. For the angular
velocity we have to multiply the torque by the inertia of the body because
bullet compute angular velocity with: torque * inertia_tensor.
  • Loading branch information
panzergame committed Nov 5, 2017
1 parent 5a4d5d3 commit 3d2e0c7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/gameengine/Ketsji/KX_ObjectActuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,15 @@ bool KX_ObjectActuator::Update()

MT_Vector3& f = (m_bitLocalFlag.ServoControlAngular) ? m_force : m_torque;
f = m_pid.x() * e + m_pid.y() * I + m_pid.z() * dv;
// to automatically adapt the PID coefficient to mass;
f *= mass;

/* Make sure velocity is correct depending on how body react to force/torque.
* See btRigidBody::integrateVelocities */
if (m_bitLocalFlag.ServoControlAngular) {
f = f * parent->GetLocalInertia();
}
else {
f *= mass;
}

const bool limits[3] = {m_bitLocalFlag.Torque, m_bitLocalFlag.DLoc, m_bitLocalFlag.DRot};

Expand Down

0 comments on commit 3d2e0c7

Please sign in to comment.