Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>WOW. So I've finally found out what the problem is.</p> <p>After hours upon hours of trying to figure out if there is a workaround by doing something fancy in the ContactListener, I decided to look and see where the PostSolve method was being called from. It comes from a class named b2Island and it comes from the Report function in that class. At first glance I spotted the problem easily. Her is the function:</p> <pre><code>private static var s_impulse:b2ContactImpulse = new b2ContactImpulse(); public function Report(constraints:Vector.&lt;b2ContactConstraint&gt;) : void { if (m_listener == null) { return; } for (var i:int = 0; i &lt; m_contactCount; ++i) { var c:b2Contact = m_contacts[i]; var cc:b2ContactConstraint = constraints[ i ]; for (var j:int = 0; j &lt; 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); } } </code></pre> <p>So yeah obviously the s_impulse var is static so it will be the same for every instance of the b2Island class ( if there is more then one ) and also it's not getting reset at any point. All the references to the s_impulse var can be seen above, so nothing else ever happens to it. But here's the point, a circle only has one contact with a polygon meaning it will only set the impulse for one contact when being reported. The other contact, if not being reset will have the last impulse of the last object to be reported.</p> <p>Basically the impulses seen on the circle is actually left over impulse from whatever just got reported. To fix it do this:</p> <pre><code>private static var s_impulse:b2ContactImpulse = new b2ContactImpulse(); public function Report(constraints:Vector.&lt;b2ContactConstraint&gt;) : void { if (m_listener == null) { return; } for (var i:int = 0; i &lt; m_contactCount; ++i) { s_impulse = new b2ContactImpulse(); var c:b2Contact = m_contacts[i]; var cc:b2ContactConstraint = constraints[ i ]; for (var j:int = 0; j &lt; 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); } } </code></pre> <p>It's as simple as that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload