1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Air flow caused by fans (game simulation)

  1. Oct 7, 2009 #1
    Hi, I'm currently taking a C++ course where we are going to make a project, we are 6 people in our group. We have decided to make a kind of puzzle game, where the goal is to move an object (maybe a ball?) through a room, avoiding obstacles and eventually reaching a goal somewhere in the room, using the things that are in the room; among others there will be fans, which in turn can be turned on and off.

    However, I'm not really sure how to simulate the air flow caused by fans. Is it possible to simulate the air flow in real time (this is only going to be a 2D game), and in that case, what model should be used (or which can be used)? Or should rather some kind of mathematical function be used, which depends on the position in the room? It would be good if the air close to the walls didn't go "through" the walls. How would you have done this?

  2. jcsd
  3. Oct 8, 2009 #2


    User Avatar
    Science Advisor

    Simulating a realistic airflow might be difficult to program, slow to run and not create a good gameplay experience: too difficult to control, design & balance the levels. You would have to visualize it well, then it might be fun to play with it.

    Otherwise you would go with a simple force function depending on distance and orientation of the fan. To avoid air going through walls, you would compute approximately how much % of the fan is visible from the ball, and modify the force with that ratio.
  4. Oct 8, 2009 #3
    Thanks you for your reply, it seems like a good idea. By not going through walls, I meant that the ball shouldn't be pressed against the wall by the air, since the air will move along the wall when it's next to it. Maybe the player won't think of that though. :)

  5. Oct 8, 2009 #4
    my initial thoughts are that this is not too bad in terms of difficulty.

    I envisage a box drawn around the fan that encompasses the zone of airflow, with variable accelerations assigned to the various areas. you can probably assume the wind to have only a single direction (ie perpendicular to the fan surface) and still maintain some realism. The acceleration would be maximum at the centre of the fan at the surface of the fan, and then be less severe at 'zones' away from this point (ie further away from the fan in X and Y direction). If you can imagine the X could be the axis that defines 'perpendicular distance from fan' and defines how objects would accelerate once in the aiflow, and Y could be 'lateral distance from fan' which would define how objects are effected by the aiflow when approaching the airflow from the 'side' if that makes sense. I reckon just experimenting with the 'drop off' (ie how accel. varies with distance in both planes) would be the best way to model it, you will soon find out what fits with realistic expectation
  6. Oct 8, 2009 #5
    I'm guessing you don't want to get too complicated, but you could run a CFD (computational fluid dynamics) simulation on your 2D room, to find a field of pressures or velocities and their directions. the ball would then be affected in the direction and magnitude of the velocity vector in that region. This could help model other objects and walls that may be in your area. I would suggest running a very simple CFD code and just use the data that it gives you to make a velocity 'map' of the room, ie. not run the CFD code realtime during the game.

    OpenFoam is a free open source CFD program that would be useful, but it'll take quite a bit of time to get results. Otherwise, I'd go with Molydood's idea. To take into account objects that are in the air flow and the ball could go behind (shielding it from the air flow, like an air flow shadow, if you will), you could make a few functions of the for zones behind objects and how you guess they would affect the airflow.
  7. Oct 8, 2009 #6


    User Avatar
    Gold Member

    Here's way of greatly simplifying the problem.

    You don't have to "model" the movement of the air. You don't care what the air is doing when it's minding its own business, you only care what it's doing when it is affecting the ball. And the only thing that affects the air is the proximity of objects.

    So the movement of the ball depends on
    - its current direction of movement
    - the force acting on it due to its proximity to a wall

    The closer to the wall, the more movement is diverted from a direction "normal to the wall" to a direction "parallel to the wall".

    The effect would be that the ball would approach the wall but, as it got closer, it would begin to turn parallel to the wall.

    Attached Files:

    Last edited: Oct 8, 2009
  8. Oct 9, 2009 #7

    A model would provide size and direction of the vector, not just the direction which is guessed based on simple geometry and normals to that geometry. I agree in keeping it simple, so what Dave says would probably be sufficient. It really depends on how realistic you and accurate that you want it and also how muvh time you have to invest. Is it a one day project or a 6 week thesis?
  9. Oct 9, 2009 #8
    It's not a very big project, maybe supposed to be 2 weeks in total, of which a lot of the work will be software requirements specification, and concentration on the object oriented part of the programming. So I think we will skip simulating using differential equations and just use some simple formula, maybe check if the is a wall in between of the ball and the fan. We just realized there is a little bit more to do than we thought from the beginning. :)

    Thanks for all suggestions!

  10. Oct 9, 2009 #9
    Assuming a 2 dimentional space, you want to split it up in a grid/ coordinate system.
    You want to have an object "fan" that defines a force field as a function of ball's distance/location/direction from it.

    You want to define obstacle object (wall) as an array of points i.e a line.

    You can calculate if a force from a fan is visible by checking if the line connecting the ball intersects the wall line.

    At every discrete moment, you want to compute the sum of forces at the ball's location that is visible at that location, to calculate its next position.

    If the new location of the ball is near the wall, apply a new force that is the equal & opposite reaction to the ball's impact.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook