How to calculate load in Box2D?
I am using Box2D (AS3 / Flash version, if it matters) and I am trying to calculate how much weight each item carries.
I know how to go through all bodies and I know how to poll the Collion Detection routines, but it seems that the collision forces die to zero when weight is applied. Is there some kind of "total static force" that I am missing?
a source to share
By using the contactResult type in the optional contactListener object, you can poll the normalForce of each element to see what forces (which essentially include weight) are being applied to the objects.
Note that sleeping bodies (such as a resting foot) will not produce contact results, but they should work fine if you disable sleep mode or only want to measure forces while in motion.
For information on how to implement the contactListener class, check the documentation.
a source to share
It's been a while since I played with Box2D, but have you tried polling GetReactionForce () for your questions?
I know that when I created a bridge simulation and I wanted the bridge to break based on the weight on it, I polled GetReactionForce () and if it was above a certain threshold, I removed the connection connecting the two bodies.
a source to share
I think all you have to do is loop through your b2Body instances and use the GetMass () method .
I'm not sure what you mean by "total static force".
As for the weight / mass, I think you apply it before any collisions when you create the body, or set it yourself using setMass (); or box2d estimates the mass based on the shape using the SetMassFromShapes () method .
HTH
a source to share