1
\$\begingroup\$

How can I generate water in a procedural 2D sideview landscape?


Here's what I currently have:

  • First generate the heightmap of the land
  • Then generate the water, based on the land

Here's how I generate the water based on the land:

  1. Assign each block a lake target for water (rain) flow.

    • First, choose the best direction.
    • Then, for each block it checks along the way, calculate the slope between that block and the next block. If that slope is zero, keep on going to create a noninteger slope, until a MAX_BLOCK_DELTA_X is reached. If this accurate slope is close to zero, we say the water drains or evaporates. Otherwise, keeping searching for the bottom of a lake, until the slope goes up again.
  2. Next, lakes are created, based on the most targets chosen in one proximity.

  3. Lastly, the lake height is calculated from the lake's amount of water (I don't know how to do this).

I see some problems with my current algorithm, like if the bottom of a lake is flat the water drains. Could this be improved? If so, how? Either way, how would I calculate the lake's height? How would I do rivers?

Edit: Caves and overhangs are not allowed.

Edit 2: This answer of my other question provides a way to identify valleys. I think this could be used, but I don't know which end to start scanning.

\$\endgroup\$
  • \$\begingroup\$ The nature of your question text doesn't seem to fit with the standard physic/math definition of 1D. What exactly do you mean by 1 dimensional? \$\endgroup\$ – Pikalek Feb 23 '18 at 20:01
  • \$\begingroup\$ @Pikalek I mean a side-view game. I guess you could think of it as 2D in that sense. \$\endgroup\$ – clabe45 Feb 23 '18 at 20:08
  • \$\begingroup\$ Is your terrain itself grid based (e.g. 2d minecraft style), or is that a behind-the-scenes approximation for the algorithm? \$\endgroup\$ – Kal_Torak Feb 23 '18 at 21:14
  • \$\begingroup\$ Are caves allowed? \$\endgroup\$ – Kal_Torak Feb 23 '18 at 21:16
  • \$\begingroup\$ @Kal_Torak the terrain itself is grid-based, and caves and overhangs are not allowed. \$\endgroup\$ – clabe45 Feb 23 '18 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.