Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Box2d Body collision force detection — Gideros Forum

Box2d Body collision force detection

kussakovkussakov Member
edited May 2012 in General questions

I am testing Gideros box2d APIs.
So I have many objects that collide with each other and I can have callbacks to detect each collision (begin, end, post, pre).
But in case I want some of the bodies to break or get destroyed I need to know the force *absorbed* by the body because of the collision.
The events only give me the fixtures that are in collision. Of course from that I can get the bodies and their velocity and mass before and after the collision.
There are tons of factors that apply (mass, velocity, friction, bounce, angles, etc.) ...

Is there a relatively easy way to get the absorbed force using Gideros APIs since not all of Box2d API as exposed?
In the Box2d manual I see how I can do it and make it real enough, but the APIs and data structures and not exposed in Gideros.

What I can do in Gideros is get the pre and post velocities, convert them in forces and do some diffs using some complex formulas...
Is there an easy way? Someone has done it and can help with suggestions/formulas/code?

Dislikes: jdlehman

+1 -1 (+0 / -1 )Share on Facebook


  • ar2rsawseenar2rsawseen Maintainer
    edited May 2012
    POST_SOLVE event callback provides a maxImpulse property, which is I guess what you are looking for.
    As I understood that is the sum of all normal impulses achieved during collision, so you can multiply it by some constant or round it, to make damage points more "prettier" and that's all.
    function test(event)
    --add collision handler
    world:addEventListener(Event.POST_SOLVE, test)
  • Thanks a lot for the info!!!
    Very helpful.

    I could not find this in the documentation.
    Do you have a link where this is described?
    Are there other event values available for this event? All I can see in the docs is fixtureA and fixtureB...


  • ar2rsawseenar2rsawseen Maintainer
    Yeah, I guess it is an undocumented feature, but there is nothing that:
    function test(event)
    	for key, val in pairs(event) do
    		print(key..": "..val)
    can't discover :D

    Of course, better await for confirmation from @atilim ;)
  • atilimatilim Maintainer
    Hi @kussakov and @ar2rsawseen,

    Sorry for the late reply. Yes it was missing and I've added this to the documentation a minute ago.
  • atilimatilim Maintainer
    And as you've guessed it's calculated as:
    float32 maxImpulse = 0;
    for (int i = 0; i < impulse->count; ++i)
        maxImpulse = b2Max(maxImpulse, impulse->normalImpulses[i]);
  • Thanks guys!
    This feature was exactly what I was looking for!!
Sign In or Register to comment.