Best way to implement 2D fluid simulation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By expaand

I am looking to create a simulation, which in large part depends on fluids. These fluids will have various characteristics, go through pipes via gravity, go through pipes via pumps, bubble in vessels, etc.

I have considered various ways to do this. So far, the best approach seems to be using cellular automata. I have seen references to doing this using a TileMap (see description), but being a newbie, am slightly confused. I see no way to have the tiles be a Node2d with a Sprite, as this write up suggests. It seems that tiles in a tilemap must refer to a pre-defined tile in a TileSet, rather than an arbitrary node. Is this true? Is there a way around this? Can I create tiles as an arbitrary Node2d scene (with a Sprite), which can be altered at run-time? Any suggestions to best do this?

Thank you!

:bust_in_silhouette: Reply From: Zylann

Don’t be confused with the “requirement” of a TileMap and cellular automatas: a TileMap may help you draw the cells, and in some cases you can re-use it to run the automata if it’s a simple one, but if you need more info than just the type of a cell, it is recommended to build your own grid in a script with all the data you need inside it (fill amount, temperature, blocking cell etc). Then, you can update a tilemap when cells change, or draw the cells yourself with _draw().

I made this prototype a while ago, uploaded it to Github so you can have a look: GitHub - Zylann/fluid2d_demo: Prototype showing a 2D cellular automata simulating a fluid

Wow, this looks fantastic. I’ll go over it and let you know how it works out. Thank you, this looks exactly like the direction I am looking for.

expaand | 2019-07-01 01:55