Question

I'm using Box2D (the AS3/Flash version, if it matters) and I'm trying to calculate how much weight each body is carrying.

I know how to iterate through all the bodies, and I know how to poll the Collion Detection routines, but it seems the collision forces die off to zero once weight is applied. Is there some sort of "total static force" property I'm overlooking?

Was it helpful?

Solution

Using the contactResult type in the optional contactListener object, you can poll the normalForce of each item to find out what forces (which intrinsically includes weight) are being applied to objects.

Note that sleeping bodies (a resting stack for example) will not trigger contactResults, but it should work fine if you turn off sleeping or if you want to measure forces only while motion is happening.

For info on how to implement the contactListener class check up on the documentation.

OTHER TIPS

It has been awhile since I have played with Box2D but have you tried polling GetReactionForce() on the things of interest?

I know that when I made a bridge simulation and I wanted the bridge to break based off the weight on it, I polled GetReactionForce() and if it was above a certain threshold then I deleted the joint connecting the two bodies.

I think all you need 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 weight/mass I think you apply it before any collisions, when you create the body, either set it yourself using setMass(); or have box2d estimate a mass based on the shape, using the SetMassFromShapes() method.

hth

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top