Switching shapes immedietly and collision results.

Topics: Developer Forum, User Forum
Jun 18, 2012 at 5:51 PM

Sometimes my game objects need to dramatically change shape. Right now I have an array of bodies that I am simply switching in and out whenever such a change is needed. If I do this near a static object, I want my switched body to push out of the static object as so:

but right now, instead I'm getting


and I don't really know what I'm doing. I've tried adding my own method to OnCollision to work this problem out and I've gotten close enough to make me believe it can be done but not close enough to work correctly. Plus, I have a feeling that's not necessary anyway and that I'm just missing something obvious to someone who understands Farseer better than I do. I should say, I appreciate the amount of things I've been able to accomplish with it in spite of not understanding it that well.

Jun 18, 2012 at 9:25 PM

There is a body in the screenshot that looks like an EdgeShape. EdgeShapes might have issues in this scenario because they are infinitely thin and you get contacts on both sides. Also they have 0 mass (not good for dynamic bodies).

I also have to deal with this problem because I need to dynamically change shapes. Honestly it's not an easy problem to solve if not for anything because it's unphysical. The physics engine made for rigid bodies suddenly finds itself with bodies materializing out of thin air and interpenetrating. The collision response should resolve that however it's not perfect in the sense that it's based on contact points arbitrarily chosen according to certain rules.

Erin Catto (Box2D) has a presentation on the ragdolls in Diablo III that you might find useful especially slides 40 and 41. http://box2d.googlecode.com/files/GDC2012_ErinCatto_Ragdolls.pdf

I'm very interested in how you might solve your problem. Be sure to hit the Box2D forums too - I've searched extensively there as well without much luck.

Jun 19, 2012 at 12:02 PM
Edited Jun 19, 2012 at 12:03 PM

Thanks for the read.  In regards to what you say about asking the engine to deal with the unphysical, I am going to reevaluate my code to see if I can scale back some of its reliance on Farseer for things that Farseer wasn't made for. You might not have that luxury but I think I might be fortunate enough.

Jun 19, 2012 at 9:31 PM

Unfortunately I don't have the same luxury. For the time being I made my body have a "perimeter" made of circle bodies that grows and "pushes" stuff out of the way. This way I don't have to deal with double sided collisions, the behaviour is quite physical as everything is done with forces and joints/motors but visually it's not really same thing so I'm on the look for better ideas. I'm afraid, though, that at the end of the day some work will have to be done to help the collision response and that will complicate things a lot. Also I'm afraid it will require custom logic and won't be applicable to the general case. Even now I believe most polygon vs polygon collision with certain overlap configurations should sort themselves out without intervention. Mostly EdgeShapes create problems.