7
votes

I was playing around with Box2D in SFML2 and realized; when I change the gravity of the world, the dynamic bodies that have been untouched for a little while aren't affected by the gravity change. I prepared a video to make this explanation more clear.

Any solutions? Do I have to make my own gravity, and why does this happen?

This is the video. Notice if the bodies don't move for a short while, they aren't affected by the more recently moved ones.

1
+1 good question was about to ask it and found this!David Kroukamp

1 Answers

6
votes

Objects in Box2D goes to sleep after they come to rest. After changing parameters like gravity you will have to wake up the sleeping objects, likely by calling WakeUp on all the objects. Objects are also woken up automatically when something collides with it, which is why the gravity seems to start taking effect after something collides with the object.