Air volume and flow between rooms like FTL

Hi :slight_smile:
I’m working on a space based tycoon game and as a part of that air management is a feature.
But i can’t figure out how to simulate air flow and pressure between the rooms i create.

in my prototype i have a central (green) square being the Oxygene provider, and around that i can place new (white) squares. the idea is that when a new white square is connected to the green square air pressure should drop and air should flow to the white square slowly turning it blue based on the current air volume and pressure.

Edit: Also each room has an Air consumption rate, so if air generation can’t keep up the rooms should slowly run out of air.
75832-air-room-screencap.jpg

it’s easy enough for me to figure out with only two rooms, but the moment that number increases im at loss :confused:

thanks in advance :slight_smile:

Did something similar in a project a few years ago. Fire fighting kind of game, where the oxygen of a room would be important for both fire and survival.

My solution was definitely not a simulation, but it gave an okay feeling and a bunch of variables that the designer could tweak. Here’s a really rough description of my solution, in case it’ll help:

It involved a controller that would know all the rooms (they registered on spawn). This controller would call each room a few times per second. It would take three steps (which wouldn’t need to be carried out in the same frame).

First it’d apply intake/usage of oxygen within each of the rooms.

Each room knew its neighbors and how much air flow could happen between them (door open/closed and such). So for the second step, the controller would then ask each room to see how much air would flow to the neighbors. These numbers were stored (oxygen gained/lost) for each room.

In step three, the controller would go over all the room again, and ask them to apply oxygen gained/lost. The reason for splitting step two and three up was to make sure that the order in which the rooms registered on the controller wouldn’t matter when progressing this.

This can have many solutions, easy solutions, which are not as precise and extremely complicated ones. First thing what comes to my mind is why not use small rigidbodies as air particles? Create them and apply slight force, they will fly into your corridors and “look like” air. You could apply smart mapping or just particle texture on those rigidbody points later on. Each of those particles could also contain some component which slightly moves them in random direction (or depending on some singleton manager) to ensure they will never actually stop.