Constantly Changing Gravity?

Hello,

I began using Box2D today and I set up a simulation which constantly changes the gravity vector based on user input.

I have about 16 square bodies moving around and stacking on each other but when they come the rest, or stack together, they never move again.
Even if the gravity vector changes drastically.

I've tried iterating through each body and calling WakeUp(); on each one but they still do not move. I'm also calling world->SetGravity(); each frame to set the new gravity vector.

Is there a technique I should use so my pile of objects will continue to move even after they have come to rest?
Sometimes your gravity is 0,0 ,right? Or when your bodies are sleeping you are trying to change the gravity?
Neosano wrote:
Sometimes your gravity is 0,0 ,right? Or when your bodies are sleeping you are trying to change the gravity?


Yes, at times it is possible to get a gravity vector of 0,0. My bodies appear to be almost sleeping, even if I set the world to not allow sleeping or iterate through each one and call WakeUp(); Is there another flag I should be setting to keep them from stopping to a halt?
Not sure, try to refilter sleeping shapes.
Double check that they are not asleep in some way. Have they hit the world boundary?
Are you scrolling the screen (in which case, you will see no relative motion)? What about if you give them a kick?
I do this every time I change gravity:
Code:
for (b2Body* b = world.GetBodyList(); b; b = b->GetNext())
   b->WakeUp();
BorisTheBrave wrote:
Double check that they are not asleep in some way. Have they hit the world boundary?
Are you scrolling the screen (in which case, you will see no relative motion)? What about if you give them a kick?


The objects may have hit the world boundary. What effect does that have? I have static, wall like, objects at every world boundary for the objects to collide off of.

Dan East wrote:
I do this every time I change gravity:
Code:
for (b2Body* b = world.GetBodyList(); b; b = b->GetNext())
   b->WakeUp();


I tried that exact code and tried re-filtering each shape as Neosano suggested, still no dice. Any other ideas?

Thank you so much for all the suggestions so far.
If they reach the edge of the world, they stop simulating permanently. Perhaps you need larger walls?
Hangar wrote:
If they reach the edge of the world, they stop simulating permanently. Perhaps you need larger walls?


Really?! I'll give that a try and report back.
Ok, so I tried enlarging my world. But, it didn't fix my problem.

A possible clue I discovered when trying the world fix is that if I remove my static bodies my dynamic bodies continue to move with changing gravity just fine.

I have 4 static rectangles which "fence in" my world near the world extents. They serve to keep my dynamic objects from leaving the world but they seem to be the problem cause?

Original thread: https://box2d.org/forum/viewtopic.php?t=2595