- Home /
The question is answered, right answer was accepted
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.
and I want to scale it into this, and save the 1 and 2 scales.
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? :D
David
It seems like you want to edit the mesh from inside a script. This is possible, and I have an idea of where to start, but from there, I've got nothing >.<
What you're looking for is probably somewhere near here
http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$eshFilter-mesh.html
$$anonymous$$odifying a mesh through this class will modify only the instance attached to your object - exactly what you want to do - but the actual code that would control it is beyond me :(
Sorry I can't be of more help, but good luck with your project!
That was a pretty good answer though. I$$anonymous$$HO you didn't need to post it just as a comment.
Answer by DavidDebnar · Jul 07, 2011 at 11:15 AM
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
Answer by Bampf · Jul 07, 2011 at 11:20 AM
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.
2) 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.
[1]: http://www.west-racing.com/megadoc/
I know and I tried both Indie and Pro waters... and they aren't flowing, when you try my code, you will probably get what i wan't :).
Follow this Question
Related Questions
How to create water physics in Unity? 3 Answers
Water Pro + Terrain Tree Billboard Shaders 1 Answer
Underwater effect question 2 Answers
Water Effects 2 Answers
2D water shader effect 1 Answer