Quickb2 collision force

Hello, I am rather new to quickb2 as I rather lately ported my game from box2d to quickb2 🙂
I have a body, and I want to make it "disappear" if too much force was put against it (if it had too much weight against it, or if something hit it very hard (maybe that'd be an impulse :S)). In box2d I knew I'd just set up a contact listener and check out the max impulse and compare it to some number, and see if it should "disappear" (be crushed), or not.

My question is, how can I do that?

Also, I am wondering whether there is documentation to quickb2 somewhere, because I couldn't find any on the google project hosting :S

If you need any clarifications, please say so 😀

Thanks in advance,
Tamper 😎
Good question!

There is (actually, was) no way to get this from QuickB2, so I've added it. It's in the latest SVN revision. Here's a simple example:

Code:
private var maxImpulse:Number = 15.0;
      
private function init():void
{
   var world:qb2World = qb2Stock.newDebugWorld(new amVector2d(0, 10), new srVectorGraphics2d(this.graphics), stage, stage);
         
   var rect1:qb2Body = qb2Stock.newRoundedRectBody(new amPoint2d(100, 100), 100, 50, 10, 1);
   var rect2:qb2Body = qb2Stock.newRoundedRectBody(new amPoint2d(100, 300), 100, 50, 10, 1);
         
   world.addObject(rect1, rect2);
         
   rect1.addEventListener(qb2ContactEvent.PRE_SOLVE, preSolve);
}
      
private function preSolve(evt:qb2ContactEvent):void
{
   if ( evt.normalImpulse > maxImpulse )
   {
      evt.localObject.removeFromParent();
   }
}


Note that you can only get this value in the PRE_SOLVE/POST_SOLVE events.

Documentation is admittedly lacking. There's a manual in the /docs folder, but it's somewhat general and probably a little out-of-date. For now, I rely on people asking questions on this forum or e-mailing me, so don't hesitate with both!

Thanks,

Doug
Will do!
Now that I know I can get help here, I'll be sure to come back if I have any more questions 😆
'till now I got all I wanted from the examples basically 😛
If you will have some documentation and a forum or something, maybe the engine could even develop better! 😀 (Just a suggestion of course. 🙂 )

Thank you again!
Tamper
Yes they both should get done 🙂
I tried evt.normalImpulse and I get an error.
dougk16 wrote:
Good question!

There is (actually, was) no way to get this from QuickB2, so I've added it. It's in the latest SVN revision. Here's a simple example:

Code:
private var maxImpulse:Number = 15.0;
      
private function init():void
{
   var world:qb2World = qb2Stock.newDebugWorld(new amVector2d(0, 10), new srVectorGraphics2d(this.graphics), stage, stage);
         
   var rect1:qb2Body = qb2Stock.newRoundedRectBody(new amPoint2d(100, 100), 100, 50, 10, 1);
   var rect2:qb2Body = qb2Stock.newRoundedRectBody(new amPoint2d(100, 300), 100, 50, 10, 1);
         
   world.addObject(rect1, rect2);
         
   rect1.addEventListener(qb2ContactEvent.PRE_SOLVE, preSolve);
}
      
private function preSolve(evt:qb2ContactEvent):void
{
   if ( evt.normalImpulse > maxImpulse )
   {
      evt.localObject.removeFromParent();
   }
}


Note that you can only get this value in the PRE_SOLVE/POST_SOLVE events.

Documentation is admittedly lacking. There's a manual in the /docs folder, but it's somewhat general and probably a little out-of-date. For now, I rely on people asking questions on this forum or e-mailing me, so don't hesitate with both!

Thanks,

Doug
I find that if either of the objects has is a bullet (isBullet == true), then this does not work.
Is that a bug, or do bullets not behave the same way?

Original thread: https://box2d.org/forum/viewtopic.php?t=6692