I ported simple Box2d Explosion simulation the function is called once when there is some event with the "Truck Car"
the problem is that the Explosion working fine but it looks like when the explosion done the "parts" of the car Returning to
the initial car position instead of bean scatter on the floor.
what am i doing wrong here ?
here is the code for the Explosion
class MyQueryCallback : public b2QueryCallback {
public:
std::vector<b2Body*> foundBodies;
bool ReportFixture(b2Fixture* fixture) {
foundBodies.push_back(fixture->GetBody());
return true;//keep going to find all fixtures in the query area
}
};
void BackgroundSprite::explode()
{
float m_blastRadius = 40.0f;
float m_blastPower = 50.5f;
MyQueryCallback queryCallback;
b2Vec2 locationPnt = _truck->truckBody->GetPosition();
b2AABB aabb;
aabb.lowerBound.Set((locationPnt.x - m_blastRadius), (locationPnt.y - m_blastRadius));
aabb.upperBound.Set((locationPnt.x + m_blastRadius), (locationPnt.y + m_blastRadius));
m_world->QueryAABB(&queryCallback, aabb);
for (int i = 0; i < queryCallback.foundBodies.size(); i++) {
b2Body* pBody = queryCallback.foundBodies.at(i);
b2Vec2 pBodyPos = pBody->GetWorldCenter();
b2Vec2 pHitVector(pBodyPos.x - locationPnt.x, pBodyPos.y - locationPnt.y);
float radDist = pHitVector.Normalize();
radDist = (radDist * PTM_RATIO);
if ((pBody->GetType() == b2_dynamicBody) == (radDist <= m_blastRadius)){
float nHitForce = ((m_blastRadius - radDist) / m_blastRadius) * m_blastPower;
b2Vec2 appForce(pHitVector.x*nHitForce, pHitVector.y*nHitForce);
pBody->ApplyLinearImpulse(appForce, pBody->GetWorldCenter(),true);
}
}
}
see what i mean in the video at 3:30 https://www.youtube.com/watch?v=3JmimxLiTpo