Before v2.3.0, the ApplyLinearImpulse(...) function looked like this:
inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point)
{
if (m_type != b2_dynamicBody)
{
return;
}
if (IsAwake() == false)
{
SetAwake(true);
}
m_linearVelocity += m_invMass * impulse;
m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);
}
So if you applied any force, it automatically woke the body. Regardless of whether it was asleep. You had to test it before hand (calling IsAwake(...) yourself) so you could avoid applying the force if it was asleep.
From the code base for v2.3.0:
inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake)
{
if (m_type != b2_dynamicBody)
{
return;
}
if (wake && (m_flags & e_awakeFlag) == 0)
{
SetAwake(true);
}
// Don't accumulate velocity if the body is sleeping
if (m_flags & e_awakeFlag)
{
m_linearVelocity += m_invMass * impulse;
m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);
}
}
The new line is the key:
if (wake && (m_flags & e_awakeFlag) == 0)
If wake == true and asleep, then awake the body.
If wake == true and not asleep, do nothing.
If wake == false and asleep, do nothing.
If wake == false and not asleep, do nothing.
This works out to: "Don't apply force to the body if it is already asleep when wake
is false."
Was this helpful?