postepenno Posted July 9, 2014 Share Posted July 9, 2014 Recently I played with p2 physics in Phaser and noticed a strange behavior of a body.Here is a scene for demonstration: clickI think that dynamic body (which is made of two rectangles) after colliding with static body should fall to the right side, but not balance on the static body. I tried to call adjustCenterOfMass() method after adding rectangles, but it didn't help. So the question is: how to make the dynamic body to behave natural? Link to comment Share on other sites More sharing options...
wayfinder Posted July 9, 2014 Share Posted July 9, 2014 Works here: http://jsfiddle.net/GWdLx/1/ Link to comment Share on other sites More sharing options...
postepenno Posted July 9, 2014 Author Share Posted July 9, 2014 Yeah, I tried to uncomment this linesp2.body.adjustCenterOfMass();but other weird things happen 1. The dynamic body falls below the bottom edge of canvas2. This body starts to penetrate with static body3. The body stops moving before touching the right edge.I have a feeling that after adjusting center of mass some p2's internal stuff brokes and render debug shifts from the actual physics position. Link to comment Share on other sites More sharing options...
postepenno Posted July 10, 2014 Author Share Posted July 10, 2014 Thanks to schteppe, here is the solution: http://jsfiddle.net/HQvXv/1/ It was necessary to addsp2.body.debugBody.draw();aftersp2.body.adjustCenterOfMass();to update debug body's render and fix the problem. Link to comment Share on other sites More sharing options...
wayfinder Posted July 10, 2014 Share Posted July 10, 2014 I'm suddenly afraid what kinds of workarounds I have coded, not knowing that debugBody.draw() call was necessary Link to comment Share on other sites More sharing options...
Recommended Posts