Discussion in 'Scripting' started by xcube, Jun 30, 2012.
Which means you can get this water?
How would you do it?
the waves aren't that hard i think, you could get that with some peril noise script, the collision on the other hand... i would start with looking into cloth collision or fluid collision...?
Thank you for your help!
I think the fluid and the cloth is too expensive for ios. (Is this true?)
I need to make simply lines as on as on video.
RageSpline for surface creation can use? But than to do waves?
the waves i would do with planes and a peril noise script on it, then just put 3 planes at different height.
and well yes the collision i think i would have a look into vertex collision, how i could collide mesh colliders with verts.
you really don't need complicated stuff like perlin noise or anything like that. Just move verts up and down nicely and you're set. You can even do this in your modelling package and export as a low res boned wave mesh. Keep it simple.
Thanks to all !
The classic solution to water ripples is to treat each vertex or pixel as a spring that is connected to the other vertices next to it.
I've coded a C# mono class that demonstrates the basic algorithm. To use it, just create an new project and attach the script to the main camera. Run the script, then position the scene view on the XY plane and zoom out until you can see the entire line of spheres. Select any sphere and drag it up and down using the Translation widget to play with the simulation.
public class Wave : MonoBehaviour
static int size = 200; // Number of vertices
static float velocityDamping = 0.999999f; // Proprotional velocity damping, must be less than or equal to 1.
static float timeScale = 50f;
float newHeight = new float[size];
float velocity = new float[size];
GameObject vertex = new GameObject[size];
void Start ()
// we'll use spheres to represent each vertex for demonstration purposes
for(int i=0; i<size; i++)
vertex[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
vertex[i].transform.position = new Vector3(i - size/2, 0, 0);
void Update ()
// Water tension is simulated by a simple linear convolution over the height field.
for(int i=1; i<size-1; i++)
newHeight[i] = (vertex[i].transform.position.y + vertex[j].transform.position.y + vertex[k].transform.position.y) / 3.0f;
// Velocity and height are updated...
for(int i=0; i<size; i++)
// update velocity and height
velocity[i] = (velocity[i] + (newHeight[i] - vertex[i].transform.position.y)) * velocityDamping;
float timeFactor = Time.deltaTime * timeScale;
if (timeFactor > 1f) timeFactor = 1f;
newHeight[i] += velocity[i] * timeFactor;
// update the vertex position
Vector3 newPosition = new Vector3(
vertex[i].transform.position = newPosition;
Thank you very much !!!
I went ahead and used Brian Stone's posted code as a base and implemented it using a procedural mesh. The water is made out of a bunch of rectangles and instead of manipulating the translate position of a sphere I used the same algorithm to update the vertex positions of the mesh. You can see the results here: http://triton.towson.edu/~mholtz2/WebPlayer/WaterDemo.html
Ignore the bad texture mapping. This is my first time coding with meshes and the whole UV mapping/shader stuff is way beyond me at this point.
Planning to add some splashes and stuff later
Great implementation, are you able to post up the source?
here is a good guide available about 2d water system ang flluvio plugin.