Water Waves 2D
- Modify how thick is your simulated fluid by seting the speed of oscilations, how fast they spread and how fast they decay.
- Set frequency, size and force of random ripples to simulate rain or uncalm water surface.
- Water can be a rectangle with a top surface or a circular surface.
- Respects project's Time Scale setting.
- Supports sprite sorting layers.
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.
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.