Creating a flowing river


I am able to create still bodies of water with the Material API, and even simulate waves with oceans.

I generated a height map that has a river that starts on a mountain and is supposed to run across the entire terrain. It has curves and divisions, just like a normal river. My question is, how can I create a flowing river, that has a current and that splashes on the curves, like it should be.

I found no examples about this on the playground, and could not find anything by searching on the internet also.

Any heads up?

Hi @Artur_Trapp and welcome to the forum.

Am presuming by this you have already seen Water - Babylon.js Documentation

Perhaps to show it is flowing you need objects on the surface to move along the water to give the illusion of current.

One possibility to simulate splashes is to use particles

Hi, John!

The particles definitely solves the splash efects part of the problem, but about the river itself, let me explain a bit more.

Let’s say I have a 1000x1000 map. At point 0,0 there is a mountain where the river starts, and runs down the mountain and across the map, ending in point 1000,1000.

From the examples, I was only able to spawn big blocks of water, not customized ones. Is there a way to have a infinity source of water at 0,0 that just spurts water to the riverway, and let gravity do it’s job?

I hope I am being clear enough, and sorry if this inquiry does not fit the website.

You would need to do a simulation, and would have to do a flow map. Your talking about doing something technical. It can be done though.

Those are some new terms to me! Do you have any links / stuff that I can read so I can get started? :slight_smile:

It will take some research then. Look up how to do a pingpong texture buffer simulation. And then do one that calculates the principal’s of water. You will still need to figure out a method for rendering it (raymarch).

If this is what you want to do you got a long road but I can help when available.

webgl fluid simulation - Google Search

I will definitely take a deeper look at it, but from your talk, it seems really complicated, and I don’t really want to get stuck at this while I could be working at other parts of the game. Do you have any other options to suggest, since you seemed to understand exactly what I need? :slight_smile:

You could always do it arcady style!

What is your real end goal for the purpose of the flowing river in the project? If it crucial to gameplay or just a visual thing?

The player is supposed to spawn on the map and clear all the monsters on it, so the rivers is more of a visual thing. But I would really appreciate if, in the case of falling on the river, the player had to struggle a bit to get off because of the current :slight_smile:
How is this arcady style? I am pretty newbie to making games in general, and this is the first time I try using water

just use a plane or something that has an animated water texture on it going in your flow direction, and then a hitbox that the player can’t see in the areas they might cross it where if they are in the box it pulls on their direction.


You can increment u,v offset of the texture in beforeRender observer callback. It will give you an effect like this one: SinkHole