flash - Box2d As3 contact listener problem -


i'm having problem box2d as3 b2contactlistener class. have class named contactlistener extends b2contactlistener , overrides postsolve method. postsolve takes 2 parameters, contact holds info 2 objects have contact, , impulse holds info contact. i'm using impulse parameter decide how hard 2 objects hit , apply damage accordingly.

here problem: if make circular, , let roll on static body have ground, drop large object anywhere on ground, circle while in motion contacts repeating impulse way large rolling. causes rolling circular objects break when shouldn't.

its if shaking static body , causing massive damage objects hundreds of meters away, affects circles.

can shed light on situation? known issue? workarounds?

i using box2das3 version 2.1a.

update: once body enters weird state of applying damage, circle touches gets tons of large impulses. once non circular come in contact body, no longer has problem. problem not on static objects dynamic , kinematic well.

update: have narrowed problem down further. contact listener freaks out , apply's mass impulses when flat edge of large object hits ground object. object, not circles, awake , touches ground tons of postsolve method calls. tried dropping box size of 11 pixels 11 pixels onto ground while circle rolling on ground. bug did not happen. if box 12 12 bug occur. if rotate box size of 12 12 0.1 degrees, bug not occur. there needs large enough contact area repro. density of box not effect anything. if box rectangle width of 10 , height of 100 , bug repro. it's size of object causing bug, possibly not area of contact size.

update: here link box2d forum post made has example swf source.

link

wow. i've found out problem is.

after hours upon hours of trying figure out if there workaround doing fancy in contactlistener, decided , see postsolve method being called from. comes class named b2island , comes report function in class. @ first glance spotted problem easily. function:

private static var s_impulse:b2contactimpulse = new b2contactimpulse(); public function report(constraints:vector.<b2contactconstraint>) : void {     if (m_listener == null)     {         return;     }      (var i:int = 0; < m_contactcount; ++i)     {         var c:b2contact = m_contacts[i];         var cc:b2contactconstraint = constraints[ ];          (var j:int = 0; j < cc.pointcount; ++j)         {             s_impulse.normalimpulses[j] = cc.points[j].normalimpulse;             s_impulse.tangentimpulses[j] = cc.points[j].tangentimpulse;         }         m_listener.postsolve(c, s_impulse);     } } 

so yeah s_impulse var static same every instance of b2island class ( if there more 1 ) , it's not getting reset @ point. references s_impulse var can seen above, nothing else ever happens it. here's point, circle has 1 contact polygon meaning set impulse 1 contact when being reported. other contact, if not being reset have last impulse of last object reported.

basically impulses seen on circle left on impulse whatever got reported. fix this:

private static var s_impulse:b2contactimpulse = new b2contactimpulse(); public function report(constraints:vector.<b2contactconstraint>) : void {     if (m_listener == null)     {         return;     }      (var i:int = 0; < m_contactcount; ++i)     {         s_impulse = new b2contactimpulse();          var c:b2contact = m_contacts[i];         var cc:b2contactconstraint = constraints[ ];          (var j:int = 0; j < cc.pointcount; ++j)         {             s_impulse.normalimpulses[j] = cc.points[j].normalimpulse;             s_impulse.tangentimpulses[j] = cc.points[j].tangentimpulse;         }         m_listener.postsolve(c, s_impulse);     } } 

it's simple that.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -