Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've recently started making game and I want to implement there an atmosphere. My plan is to include in game many compartment, tubes and ventilations.

For example if I open and airlock from room with zero pressure to the room with high pressure, I will feel heavy knock back. Or I can mix gases in room and units human alike wouldn't be able to breath and will die.

I have idea how to do it, but it won't be that sufficient and real. Do you know any tutorials or read y free-open source codes to do. I don't need any real atmos, it just should feel like real.

Addition: To make less confusion this is the small list what I want to implement:

1) Gas pressure and how it affects enviroment( unit moving, making damage to units ).
2) Simple gas mixing ( I would like to implement 4-5 different gasses ).
3) And some sort of in gameplay devices to affect atmos and check its state.

Yes. It is 2d game.

share|improve this question
I guess what I would do first is keep track of information for each room (pressure, a list of possible gases and their concentration percentage, and a weight which represents the room size). Then at every update loop check which rooms are connected through open doors and windows and normalise them (gasses begin to disperse evenly and air pressure averages out depending on the weight of a room). When a door or window is first opened you can apply the pressure knock back forces and during the update you can also apply gas effects based on the rooms current concentration. – Benjamin Danger Johnson Jul 17 '13 at 16:29
up vote 3 down vote accepted

It depends on what kind of game you are making. For example, a smallish 2D game might require a different approache than a large 3D one.

My initial suggestion would be a kind of fluid simulation. A grid with values for density, pressure and velocity for each gas. A very good resource for this is a stable fluid solver from Jos Stam. It even has code. The fluid solver can be 2D or 3D, but I would suggest solving a 2D system even if your game is 3D (if possible).

A 'cellular automata' is another approach, similar to a fluid system but can be a quite a bit simpler. Perhaps look into "lattice gas"

If your world is particularly large, you might consider and even more simplified system, such as running the fluid simulation on a very simple waypoint like graph. Although again, this highly depends on your game.

share|improve this answer

I would make each room a node, (or break each room into nodes for finer granularity) and create a simple Cellular automaton to move gases around. Nodes of equal pressure exchange different gas types at a slow rate, until equalized. Otherwise, gases will move from high to low pressure. Movement between nodes can easily be determined and forces applied to anything inside of those nodes.

I would keep a simple table for each node that contains the percentage of each type of gas that's in that node. Keep it simple and deal with percentages, trying to calculate the density of different gases and how much of some other type of gas they should replace gets too complicated. Nodes only go below 100% when there's vacuum. So a node in space would be 0%.

With this percentage based approach, it's easy to define triggers for the units within the nodes. Say humans need x% of gas y and no more than i% of gas j.

share|improve this answer

For every environment (like rooms), you can keep an info of gas pressure. High value for room with high pressure etc.

Then, you can apply a force through windows and doors (you know where they are). You can omit walls since nothing will come through it.

The formula of this force might depend on 3 things. Pressures of 2 different environments and distance to border (where these two environments meet).

If you have just opened the door, the pressures are different and you are exposed to maximum force. So something like:

Force (you, pressure1, pressure2, distance){

force = absolute(pressure2-pressure1) * 1; applyforce(you, force);}

if you are just at border, you can keep distance 1, and if you are away, you can decrease the distance up to 0. This way, when you are far enough (which you will decide), multiplication will be zero and no force will be applied.

Meanwhile, you should also make the pressure stable within a certain amount of time, since gases will mix and there will be no force (except gas pressure to objects, which is not important, they are from all directions and likely to cancel each other in the end)

After a while, when pressures are equal, the pressure2-pressure1 thing will be zero and again no force will be applied as expected.

For the unit moving thing, it is the same. When this force is applied onto something, depending on weight and shape of object and friction, it will move accordingly. These should be specified by you for different type of objects.

Basically you need to know where such affects occur (enterance to rooms) and define static force vectors for it.

My idea might be wrong though, just to help you

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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