Disposing/Remove of Static Body with Dynamic Body on top

Topics: User Forum
Jul 23, 2012 at 1:07 PM

Hey folks,

 

I have run in to an issue where i have a dynamic body on top of a static body, but when i remove it the dynamic body doesn't update and fall down. As soon as i try to move to dynamic body it then updates and falls down.

Have i missed something? How can i get this dynamic object to update automatically? Do i have to get a list of all the dynamic objects touching my static one and manually wake them up? Am i removing the static body in an incorrect manner.

Here is the offending code.

 

            input.BindMouseButtonToAction(MouseButton.Left, ButtonState.Pressed, () =>
                {
                    var fixture = physicsWorld.TestPoint(camera.ConvertScreenToWorld(input.MousePosition()));
                    if (fixture != null)
                    {
                        fixture.Body.Dispose();
                    }
                });

Any help would be great.

 

-Thanks

Jul 23, 2012 at 2:12 PM

Is the dynamic body sleeping? If so, set it awake right before you remove the static body.

Jul 23, 2012 at 2:28 PM

But then whenever i move any static object am i going to have to find all bodies it is colliding with and wake them up.

Is that the only method? I assume there must be an easy way to get the bodies contained in the contact list then?

Jul 23, 2012 at 3:03 PM

If you're just moving the body, you should be using SetTransform (assumung you don't want collisions to be triggered). I'm not sure if this signals a wake or not, but if the bodies are sleeping then there's only two thigns I can think of to do:

1) Set the bodies awake.

2) Just wake everything up if this OK for performance (they'll sleep again soon, anyway) [Or wake everything up within a radius of your object]