12
\$\begingroup\$

I am experimenting with weather conditions in a game of mine, and I was impressed by the way Starbound handled the rain. Basically, when rain hits the ground, it's either dispersed horizontally (and absorbed by the ground), or it creates piles of water (when raindrops land inside a hole in the ground).

This video demonstrates this clearly: http://imgur.com/gallery/CKCGKbG

I know how to make rain fall and check where it hits the ground, but that's where I get stuck. My question is: how could this have been created? And how could one model the water flow so perfectly, without killing performance?

Thanks in advance!

\$\endgroup\$
  • 1
    \$\begingroup\$ The key is the fluid dynamics system. I suspect that when a raindrop hits the ground, it generates a small amount of water at that position which is then processed by the fluid dynamics system as usual. On flat surfaces it's countered by evaporation, but when slopes cause water to concentrate in an area, the influx is stronger than evaporation and puddles start to form. \$\endgroup\$ – Philipp Oct 2 '16 at 10:51
9
\$\begingroup\$

Starbound's water system is actually 2D tile based cellular automata. Each tile on the screen that does not contain a front tile layer, is capable of holding water. The amount of water is calculated via cellular automata.

More information on this technique here:

http://www.gamasutra.com/view/feature/134736/an_intro_to_cellular_automation.php

http://www.jgallant.com/2d-liquid-simulator-with-cellular-automaton-in-unity/

As for the rain drops, those are particles. They serve mainly to fake that there is actually water falling from the sky. The water accumulates only because the game knows it is currently raining. The individual drops have nothing to do with the actual formation of the water pools.

The way they get it to accumulate, is by determining where there are holes in the top layer of the ground. If there is an area that can accumulate water, the cells in that area increment their water levels accordingly.

Starbound also deals with water pressure, and their rendering technique is pretty amazing. They have the best 2D implementation of water simulations physics using cellular automata that I have ever seen.

Here is a primitive view of a liquid physics engine, utilizing the above mentioned cellular automata technique. The rendering portion becomes a little more complex, as your water is represented by a numerical value.

http://www.jgallant.com/images/pressuretest.gif

In this example, a very simple improvement would be to hide water cells that have less than 1 full unit of water in it's tile if there is no solid tile below it. But then, you are hiding the water flow. Instead of hiding it, you would have to determine how the water is flowing, and then draw the appropriate water sprite in its place.

\$\endgroup\$
  • 2
    \$\begingroup\$ To add to the fact that the raindrop particles fake the water falling effect: the little droplet splashes on the surface are also not related to the actual rain particles but a separate effect. The combination makes it look as if the droplets make the splashes. \$\endgroup\$ – Felsir Oct 5 '16 at 20:46
  • \$\begingroup\$ Wow, that's exactly what I was looking for. I thought I would have to resort to some overly complex fluid system based on particles, but grid systems seem to work just as well. Though, to add water pressure I guess you just need a second array that stores pressure values and flows from high pressure to low pressure places? If so, that still shouldn't be too hard for the computer. \$\endgroup\$ – Pandaqi Oct 7 '16 at 15:40
  • \$\begingroup\$ No, all you need to do with pressure, is to add a rule such as, a tile is allowed to contain more than 1 full unit of liquid. If that tile has more than 1 full unit of liquid, and is not able to flow as per the normal set of rules -- then make it flow upwards. Adjust so that it allows more water to flow based on the pressurized value of that tile. \$\endgroup\$ – jgallant Oct 7 '16 at 15:48
3
\$\begingroup\$

There's a bunch of ways to approach this. As always 'it depends'

And so I guess one way would be this way.. Given an arbitrary 'dip in the ground' Overlay a 'water box' that bounds it. The ground and waterbox are drawn in layers so that the ground is shown first, the waterbox after.

every time a water drop hits the dip in the ground add one to the waterbox. When the waterbox reaches a magic number, add a line of water. So say 10 drops land in the dip, this adds one line to the waterbox.

So say the waterbox is 32X32 pixels. Add one line of water colour from 0,31- 31,31. Another 10 drops, draw a line from 0,30 - 31,30. So as drops accumulate, you build up the waterbox from the bottom until its full.

Hope that makes sense.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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