Advertisement
  1. Game Development
  2. Unity
Gamedevelopment

How to Create an Animated Waterfall

by
Difficulty:BeginnerLength:ShortLanguages:

Are you ready to fight against another dangerous enemy of your game? An enemy? Yes—it's the performance!

As we discussed in my last article, poor performance will kill a great game.

On mobile and web platforms, especially, performance is a really big issue. But this is not only a current issue: in the past, PCs and consoles were less powerful than today. And by searching in the past, we can find great and smart solutions.

Today you'll learn how to put a great waterfall inside your game without degrading performance.

We'll use the below items:

  • Unity 5 (it's free: download it now!)
  • A texture like this:
The Waterfall Texture

And... stop! It's kind of magic!

The Waterfall Effect

Check the video below:

This is a great waterfall, isn't it? I love it. I would really like to put a waterfall like that in my game. But how?

We can start with a deconstruction technique. Look at the scene with attention: what parts is it made of?

  • the river (on the top)
  • the waterfall (vertical)
  • the river (on the bottom)
  • some steam where the waterfall ends
  • some spray where the waterfall starts and ends

We can do it with a couple of items, without killing the performance.

But first, I'll explain to you...

Why Can't We Use "Real Water" on Mobile?

In a 3D game, water is made with specific shaders and components (like particles) that cost a lot of time during the rendering phase. For this reason, high-level solutions are not recommended for a mobile game.

This tutorial is written in order to suggest a simple way of putting a waterfall inside a game without losing FPS.

1. Create the First Scene

  • Open Unity
  • Create three planes as in the example below
The waterfalls structure
  • Create three materials with the Mobile/Particle/Alpha Blended shader (called Waterfall_bottom, Waterfall_main, Waterfall_top).
  • Add to all three materials the texture "waterfall_texture".

2. The Code

  • The "core" of this idea is to use the Animated UV Map.
  • Create a new script in c# (name it "ScrollUV").
  • Inside, put this really short code:
  • Save the file and add this script to all planes.

3. Adjust the Numbers

You must adjust the tiling of the textures in the three materials conforming to the size of your planes.

Adjust the tiling of the texture is an important step

Also, you must adjust the speed: the vertical plane should be faster than the others.

The final effect should be like this:

The final effect

And... it's finished. Press play and see the result.

Bonus: A Particle System

If you want to add some particles in order to add more effects to your waterfall, here are a couple of ideas.

Note: the textures are made with Paint or similar. They are very, very simple, so anybody can create textures like that.

Spray

Create a PS and named it "PS_spray". Move it in your scene until it is at the bottom of the waterfall.

Use these parameters:

Particle System for spary effect

Duplicate it and move it until it's at the top of the waterfall.

Steam

Create a PS and named it "PS_steam". Move it in your scene until it is at the bottom of the waterfall.

Use these parameters:

Particle System for steam effect

Bonus 2: Lava

This is a simple trick to have a lava waterfall: change the color of the texture like this:

The Lava Texture

You may want to increase the max particles of the steam; and remember to remove the spray particles.

Conclusion

Sometimes the quick solution is also the best solution.

This tutorial, for example, was born in the past, during the '90s, when PCs were less powerful than today and developers had to find some creative solutions to work with their limitations.

The "trick" of an animated UV map is perfect for a lot of situations.

For example, you can use it to animate a background. Or, if the texture has more tiles (like a "frame from a cartoon"), you can create a short cinematic sequence. The only limit is your imagination.

Why is it very important to understand techniques like this nowadays? Because always, in game dev, you'll find bounds that you'll have to find a way around. And studying the past is, in my opinion, the best way to learn for the future.

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.