Saturday, December 12, 2015

flash - Water simulation in Isometric game



I'm creating a game in Flash AS3 in which the player needs to modify land in order to direct the water in the right direction.


However, water simulation is a new topic for me and I'm kinda stuck. It doesn't have to be like realistic water, with ripples and stuff, but it has to flow, and if there's enough water, it needs to rise.


I've thought up two different types of water:



  • A Spring: Infinite source of water. Used for simulating seas and stuff.

  • Water block: Just one unit of water.


My current implementation shows how I'd like the water to spread, but it doesn't rise, and doesn't allow for finite water. Also, the spreading isn't accounting for any amount of water, it just duplicates instead of actually moving units of water.


I'm curious to how you guys would solve this problem. Any examples/pseudo-code is always appreciated.





Current version: http://dl.dropbox.com/u/319897/ProjectWater.swf You can manipulate the land by pressing left mouse. And can simulate one step of water at a time by pressing A.


Source of the water part: http://pastebin.com/Js2kYt4y



Answer



You need to check out cellular automata, and possibly fluid dynamics. Tarn Adams implemented a cell based fluids system in Dwarf Fortress, and those are the tools he claimed to use in an interview I read some time back (and also in 3 dimensions as per your use case). I think for your purposes, cellular automata (self-replication/propagation of water cells) will be enough. Cellular automata are basically what you see in the classic game of Life by John Conway.


The roguelike development community has a ton of information on this sort of stuff, because those games are inherently cell-based. I believe there is a rec.games.roguelike mailing list somewhere on teh webz where you could get some in depth info.


Also suggest you check out the Voxeltron videos on youtube, one of them (there are only about 2 or 3) shows liquid lava in motion. If you were to use small enough subcubes within your main cubic grid, you could get pretty cool non-blocky water going, using sine waves and the like for surface motion. Once again, for propagation you'd be using cellular automata techniques.


For an introduction to CAs, check this out.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...