I'm currently writing a small game with box2dweb and I need some direction for this: I'm throwing a Box and have to hit a specific place and trigger an event when the object that's been thrown isn't moving anymore, "fell asleep" so to say.

What's the proper way / best practice for this?

I'm currently thinking of asking the b2World whether an Object is within a specific AABB and then wait a few seconds, check if it's still there and then trigger the event. But this seems to me like the roundabout way and the object might still be moving inside of that AABB and eventually even drop out of the AABB.

  • 2
    \$\begingroup\$ can you not check to see if the object's velocity is 0? \$\endgroup\$
    – Eric B
    Nov 28, 2012 at 18:15

1 Answer 1


Probably the most reliable way is to modify the source of box2DWeb and have it fire an event when it puts an object to sleep (or maybe this already happens, I don't know much about box2DWeb). When you detect this event, check to see if the object is within the specific AABB you want.

It looks like the live demo found here changes the color of the object when it goes to sleep. Check out the source for that demo and see how it's being detected.

Alternatively, you can poll the object's velocity, when the velocity is all 0's, check to see that it's inside the specific AABB you want.

The latter method may be good if you want to check when the object is "close enough" to stopped. Then you can test for velocities less than a threshold value to see if it's pretty much stopped. This will give you better response times if an object is taking its time coming to a stop (as can happen with these simulations).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .