Scaling water flow parts

Hey! First when you saw this, you probably tought that some dumbass cant scale :). Well I don’t wanna totally normally scale. I wanna do something like this.

I have an box.

Normal box.

and I want to scale it into this, and save the 1 and 2 scales.

Scaled box.

If you are wondering why do I need this. I need this to create flowing water. Because I need something pretty fast, and this will do. The algorithm will scale the side 2 saves the number than makes another box next to it with scale 1 that will be big as scale 2 from the one before etc. Is it possible? If so than how? :smiley:

– David

Cube deforming webplayer

Ok I made it…I needed to understand how the vertices work, and than it was easy :). If you wanna test it, just create a new .js script and add it to some cube… than with adjusting the V1 and V2 floats you can make the cube change. And for collider I use mesh collider and than I update it each frame. The whole thing runs totally smoothly, when i have the algorithm for water finished ill post a demo on the forum.

var newVertices : Vector3[];

var v1 : float = 0.0;
var v2 : float = 0.0;

function FixedUpdate () 
{
	 var mesh : Mesh = GetComponent(MeshFilter).mesh;

    newVertices = mesh.vertices;
	
	newVertices[6].z = v1;
	newVertices[7].z = v1;
	newVertices[12].z = v1;
	newVertices[14].z = v1;
	newVertices[18].z = v1;
	newVertices[20].z = v1;
	
	newVertices[4].z = v2;
	newVertices[5].z = v2;
	newVertices[10].z = v2;
	newVertices[11].z = v2;
	newVertices[17].z = v2;
	newVertices[23].z = v2;

    mesh.vertices = newVertices;
    mesh.RecalculateNormals();
}

function Update ()
{
	var mesh : Mesh = GetComponent(MeshFilter).mesh;
	transform.GetComponent(MeshCollider).sharedMesh = null;
	transform.GetComponent(MeshCollider).sharedMesh = mesh;
	
    mesh.vertices = newVertices;
    mesh.RecalculateNormals();
}

– David

  1. SilverTabby is right, modifying the mesh will do what you want. To match your illustration, you just need to move one of the vertices. See the documentation that SilverTabby linked to for an example.

More mesh deformation example code can be found here on Unity’s website.

To do it without coding it yourself, there’s a popular product in the Unity Store
that deforms meshes for you.
There are also people selling other water assets on the store.

  1. Have you looked at the water assets that come with Unity? They get a flowing effect just with texture effects. Unity Pro’s version of the water assets add reflection, and have an ocean example that deforms the mesh to make waves.

Hope this helps.