Water Waves 2D

Web demo Get it on the Asset Store
Water Waves 2D is the effect for simulating 2D water surfaces with configurable properties, such as colors, sounds and properties of the waves.

Features

How does it work?

It creates a 2D mesh with a trigger collider and buoyancy effector and keeps an array of points. On trigger enter and exit it applies forces to the points, calculates their new positions based on spring equations and updates vertex positions of the mesh.

What it cannot do?

Right now it doesn't support texturing or any kind. It only uses the default sprite shader and doesn't not have shaders to create any effects. It also does not generate any particles yet. These features can be added in the future, especially if they'll be requested.

How to use

To create new Water Waves 2D object in your scene, click on GameObject menu in Unity window, then go to 2D Object and then click Water Waves 2D. That's it, now you have an object that will react if other 2D physics bodies enter or exit its area.

Configuration

The shape of water lets you choose between surface and circle. The waves spread in different ways for each of those.

Size/Diameter lets you set the size of your object.

Resolution defines number of points that are being calculated. More points will result in smoother water but more calculations per frame. Also keep in mind that wave properties depend on how close the points are and as you increase the number of points the waves will look smaller, which can be adjusted in Wave Properties section by modifying Spread speed and Spread damping to achieve desired behaviour.

Line thickness is the width of the surface line. Setting it to 0 physically removes it.

Line color, Outer color, Inner color will let you set colors for the surface line and the gradient for the water. The mesh is being colored using vertex colors.

Wobble speed, Wobble damping, Spread speed and Spread damping adjust the behavior of the waves. These numbers are used in spring equations to determine how fast the points will oscilate and how they'll affect their neighbors. The speed values are spring constants, they're not expressed in any particular units. The damping values set how much of current velocity will be subtracted on each step of the calculations for each point. Tooltips for these fields will let you know the range of acceptebla values. Extreme values can cause unexpected behavior. You'll be able to try and see for yourself which values work best for you.

Random ripples section will let you set Frequency, Size and Force of random ripples that appear in random places on the surface of the water as if they were impacts with the colliders. Frequency sets impacts per second, Size sets the width of the virtual object that creates the wave and Force sets the speed of it.

Audio section allows you to remove, add or replace the sounds the object produces on trigger enter and leave. There's two arrays for audioclips: one is used OnTriggerEnter and another OnTriggerExit. Both can have as many or as few audioclips as you want, including zero. If the array has multiple audioclips the one to play will be chosen randomly each time.


That's pretty much it. If you'll have more questions you can always email me or contact me on Twitter. Feel free to get in touch if you encounter a bug or know how I can improve this asset.

Web demo Get it on the Asset Store

If you like this asset, please consider giving it a rating or a short review on the Asset Store. This will help others to discover it and make sure I'll keep improving it.