I have a Box2D project that is about to create a view where the user looks from the Sky onto Water. Or perhaps on a bathtub filled with water or something like this. The Object which holds the fluid actually does not matter, what matters is the movement of the bodies, because they should move like drops of grease on a soup, or wood on water, I can even imagine the the fluid is mercurial, extreme heavy and "lazy".

How can I manipulate the bodies (every frame or time by time) to make them move like this?

I started with randomly manipulation their linear velocity, but I turned out that this not very smooth and looks quite hard.

Is it a better idea to check their velocity and apply impulses? Is there any example?

Greetings philipp


If you are describing a top-down, or bird's eye, view, then the solution is simple. Fill your scene with dynamic objects and do not apply gravity to the world at all (set gravity to 0). Then, each update step in your game loop (but never during b2World.step()), apply a force or impulse. This will set them in motion and Box2D will take care of the rest. If you want them to not continue moving forever, set some damping (probably a higher damping for a thicker fluid). This will allow them to slow and come to rest until you apply more forces to them. The rest is just art.

  • 1
    \$\begingroup\$ you are right, totally I am quiet sure now (that is why accepting needed time). Some Damping and some Impulses did the trick. \$\endgroup\$ – philipp Sep 19 '12 at 13:23

You might want to take a look at some buoyancy examples for box2d.


some info: b2BuoyancyController http://personal.boristhebrave.com/project/b2buoyancycontroller

  • \$\begingroup\$ Thanks! I have already seen this, its cool, but my view is from from the the top onto the surface of the fluid, so this is a sideview... Or can I use it for a topview too? \$\endgroup\$ – philipp Sep 18 '12 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.