How to Create 2D Waves in Unity With a Plugin
Are you looking for a way to add moving liquids like water or lava in your Unity 2D game? Well, I just created the perfect plugin for you then!
Here are some examples of the things you can create with the "2D wave generator" plugin. Each of these waves was created in less than 10 seconds.
In this short article we will see how this plugin works. Spoiler: it's ridiculously simple.
Let's start to see how to get the plugin in your Unity project.
- Go to my plugin's page on the asset store.
- Click on the buy button.
- Import it in Unity.
- And you should see this in your Project.
The important thing here is the wave prefab at the bottom.
Add the Wave
Simply drag and drop the wave prefab to your scene, then position and scale it however you want. The idea is to set it exactly where you want the waves to appear. You can also change its color and material if you need to.
Then press play to see the default waves.
That was easy!
Tweak the Wave
The last step is to tweak the parameters of the waves to fit your needs. You can see them in the inspector when you click on the wave prefab.
- Amplitude: how high the waves are.
- Period: the distance between each successive wave.
- Speed: the speed at which the waves move.
- Smooth: how smooth the waves are (a lower number will have better performances).
- Direction: the direction of the waves, either left or right.
You can change them while in play mode to see the result in real time.
How it Works
For your information, the wave is created programmatically with a mesh. Then all the points at the top of the mesh move up and down to follow a sine curve.
Here's a low resolution wave to better show you how this works.
As you can see the plugin is super easy to use. If you want it, you can download it here. And if you try the plugin, please make sure to leave a review. Thanks!