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

Im stuck developing an important detail of my game water: Making it flow downwards!

Considering a typical 3D world in wich water tends to go towards gravity g=(0,-1,0) , and having the normal of the water surface n=(x,y,z), how can I calculate, based on that, the water flow direction vector?

As an example, consider this badly-done graph (In 2D, though)

Water flow graph

Update: I'm considering a very simplified water surface (Just a plane: No ripples, no waves, no pressure, etc.). If any of those needed to be applied, the answer would depend on more factors than just the normal.

share|improve this question
up vote 12 down vote accepted

One way to do it, considering you want a 90° angle, is to find the cross product of the normal and gravity, normalize it, then cross that with the normal again.

In your diagram, the first cross will produce a vector pointing into the screen, and the second cross will produce the flow vector.

An interesting side-affect of using cross products is that the flow vector will be longer the further the normal vector is away from vertical, which could be used for flow speed?

This assumes you are using a right-handed coordinate system, if your system is left hand, the intermediate vector will point out of the screen instead, but will still produce the same result.

share|improve this answer
Yeah, that looks great. Even it looks so simple when explained, I spent like half an hour thinking about different (wrong) ways of doing it, and i missed this one completely. Thanks! – Ivelate Mar 29 at 20:30
This won't produce anything that remotely resembles what you would normally think of as a direction of flow. To see why consider what the surface normals of a river flowing across your map would be and how they're going to differ in a river flowing east to west and west to east (i.e. they're not). – Jack Aidley Mar 30 at 12:58
What if the normal and the gravity are (anti)parallel? I can't help but find no sense in this answer. As @JackAidley said, there are infinitely many possible flow directions given a normal. – Margaret Bloom Mar 30 at 14:36
Given the simplified model presented in the question, I believe this answer will produce the vector they were looking for. @Margaret If the vectors are (anti)parallel then the flow vector will be (0,0,0) which would be the expected flow in a flat body of water, i.e. a pond/lake – KingPin Mar 30 at 19:45
@KingPin: A river is also a flat body of water, and most lakes flow out to rivers. – Jack Aidley Mar 31 at 8:50

You cannot determine the direction of flow of water from its surface normals, you will need to store additional data.

A simple trip to look at a river should be sufficient to convince you of this. Any difference in the surface normals merely reflects rippling in the surface, the mass of water continues to flow in the same direction. But the underlying reason is because the normal defines a plane and you need a vector of flow. Your vectors are about the shape of the surface not the movement of the water.

share|improve this answer
True, you are right. I was considering just a very simplified water body (No ripples, no waves, no pressure, etc.), but certainly in real life this calculation wouldn't be so simple. Im going to update the question to make those details clear. Thanks for your input! – Ivelate Mar 30 at 15:07

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.