Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At this point the platform and programming language don't matter I would just like to know if something out there exists for this. Any help is appreciated.

share|improve this question

closed as off-topic by Kromster, Josh Petrie Jan 20 '15 at 20:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Kromster, Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

I've implemented a custom 2d fluid engine. I was able to get a working example up using this paper on viscoelastic fluids and the code from Flui°D°emo as a template. However, the fluids are not as stable as I would like and code could use lots of optimization love (multicore processing, cache friendliness, etc). What I want is a library that has done all that already, so that I only have to integrate it with Box2d and my game. – deft_code May 30 '11 at 12:43

Look into what Q-Games used for Pixeljunk Shooter. It is a 2d game with pretty involved fluid physics. I'm not sure if they used a homegrown or middleware physics engine, but the information is probably out there somewhere.

share|improve this answer
They have used a homegrown engine, but have included techniques that can be applied using any physics engine en some custom code. The actually gave a very informative talk about their fluid dynamics at GDC (slides here: – ghost May 28 '11 at 8:39

Well i havn't looked into this, but i know for a fact that almost any physics engine can emulate the idea. Box2D, etc.

Basically have particles bouncing around, off surfaces and eachother (faster for gasses) but also give them a constant gravity like effect (liquids would all have the same, but some gases you might want to rise slowly).

If you link up the outer particles you will get a polygonal shape representing the mass


if you simply draw a pixel or particle graphic over each particle, you can achieve a cloud effect for the mass instead.

share|improve this answer
This answer is not suited for real time games in a practical size. – AttackingHobo May 28 '11 at 6:32
I am not sure why you'd say that, as fluid dynamics are very often modelled as particles. For examples see the nvidia tech videos on fluid particles on youtube, the program Algodoo (formerly called Phun) or the talk Q-Games gave about their PixelJunk Shooter game (slides at In the latter case, Q-Games shows how they construct a polygon out of a collection of particles. I would think that this verifies that this answer is quite valid for realtime implementations IMHO. – ghost May 28 '11 at 8:45
WOWOW why the downvotes? I'm not raging, just want to know why. It is a realistic technique and is used. – Randomman159 May 28 '11 at 10:22
"particles bouncing around, off surfaces and eachother (faster for gasses)" that sounds like you are describing fluids on the molecular level, and while a naive approach could work with baked simulation, it wont work well for real time games. Particles are fine as long type of simulation is correct, "bouncing arround" does seem like it would work with macro particles. You also grossly misrepresented how to simulate density. – AttackingHobo May 30 '11 at 3:54
Particles works good enough Was used in FLT:s latest demo as described in This implementation might be a bit heavy weight, but simpler approximations as in the Pixel Junk Shooter GDC talk should work fine. – void May 30 '11 at 5:52

The only library I could come up with that specifically deals with fluids is Fluidic. It is pretty alpha and only has one release, though. The physics library Bullet supports 'smoothed-particle hydrodynamics', a technique used to model fluids. Although the library is geared towards 3D, you could apply constraints to one axis to make it work in 2D.

My recommendation would be, as I already mentioned in some comments on other answers, to use a standard physics engine like Box2D or Chipmunk and use a number of circles to model the water (with gravity) or gas (without gravity) and combine these together into one water or gas body. You can apply some constraints on the individual bodies to make them 'clump' together so you can simulate viscosity. Have a look at this video to see how the individual bodies (modelled as squares in the video) work together. Note, however, the technique used in this video is not the same as mentioned in this paragraph. You can use the video to get a feel of how the circles interact with each other and try to mimic this with the constraints present in the physics library used.

The interesting part comes when you want combine multiple circles into body of water. The most straightforward solution I can come up with is drawing each circle as a metaball so they appear as part of a larger body. You can find the math and some example code behind these bodies here.

share|improve this answer
The video you linked to is using much more than just lots of circles. He uses a technique known as SPH. The blaze port of Flui°D°emo uses Box2d to find collisions and apply forces but uses SPH methods calculate forces not Box2d's rigid bodies. – deft_code May 30 '11 at 12:35
You are absolutely correct in that regard. The video was meant to be illustrative instead of an implementation example. Thank you for mentioning my mistake and I have updated the answer to prevent further misunderstandings. – ghost May 31 '11 at 14:31

It's been a few years since this question was posted, but I came across it while searching, so I thought I'd update it.

Google released LiquidFun (open source) for the Box2D system. It has some limitations, but it's a quick way to get started with liquid, sand, etc particles with pretty decent performance.

PixelJunk has a great approach, but it's a private library. They shared an amazing level of details in their talk at GCD 2010.

share|improve this answer

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