- Home /
Air volume and flow between rooms like FTL
Hi :) 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.
it's easy enough for me to figure out with only two rooms, but the moment that number increases im at loss :/
thanks in advance :)
what im basically looking for is some sort of fluid simulation. but all the other tutorials and answers about it is more focused on getting the movement of the fluid right which is not really relevant for me, since my fluid is never seen and only simulated through variables.
No one?? I'm not asking you to write my code, just to be pointed in the right direction :)
Answer by NerdClown · Aug 12, 2016 at 11:04 AM
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.
In my game the only way to close of airflow would be to disconnect a section from the provider, but that might be similar to a Open/closed door :)
I was split between making one controller object or giving each room an Airflow script and initially opted for the latter, but i can see how i could organize it better in one script :)
where i am really stuck is how i would go about calculating the intake/output.
right now im thinking something based on pressure, like:
Pressure = Output - OxygeneLevel / intake
and then calculate how much would be needed to take in pr. sec or how much would be needed to put out pr. sec. the problem lies in, in order to calculate pressure i need output and intake, which i need pressure to calculate :/
thanks for the reply :) you should have put it as answer :)
Thanks, converted to answer :)
I did something like
(oxygenRoomA - oxygenRoomB) * timeSinceLastUpdate * oxygenFlowPerSecond
With airFlowPerSecond being between 0 and 1.
But my task was a bit different from yours ... everything had the same pressure, but the concentration of oxygen in the air would rise and fall.
Thanks :) I see the difference :) but combining what you made with my idea with pressure i now think somethink like: the provider room always has a constant intake, so calculating its pressure based on the adjecent rooms Oxygene level should be possible, and then calculate how much spare oxygene it has. Set that as the output devided by rooms connected to the provider. And then calculate the new rooms pressure based on intake and connected rooms oxygene level.
The most important thing for my script is that the air allways flows to where the pressure is lowest :)
Answer by YoungDeveloper · Aug 12, 2016 at 10:54 AM
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.
I think you misunderstood my question :) I don't need to see the actual air :) All i want is to figure out a way based on adjecent rooms Oxygene level to tweak my current rooms Oxygene level variable.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Pipe flow simulation shader 1 Answer
AirPlane Script? 2 Answers