- Home /
Answer by Llama_w_2Ls · Oct 11, 2021 at 07:22 PM
Water, like in minecraft, is simulated using cellular automata. Essentially, each 'cell' or block, is moved individually, following a certain set of rules. The rules for water would be:
If block beneath is air, convert block beneath to water
Else if block to left/right/back/front is air, convert those to water (with a different level of water)
Else, don't move
The first rule is to allow water to fall.
The second, is to allow water to flow, essentially filling its container by flowing out to its neighbours. As it flows, the amount of water it has needs to decrease. This way, it will terminate when the water can't flow any further.
Whenever you go through one generation of your automata, you need to create a copy of the data, and only alter the copy, but read from the original. This way, any changes during the simulation won't affect how the next block will react.
also, how would i do that in my unity project? i can share the code...