- Home /
How can I make water waves ?
Hello
I have some questions about creating water-waves. I know how I can make normal waves to let my water look like it's moving in a direction. This is my Script: (It also has some Functions to let my Water looking a bit random)
#pragma strict
var Speed : float = 0.001;
private var offset : float;
var offsetSpeed : float = 0.1;
// How smooth should it be
var Smooth: float = 20;
// Speed of the Wave
var SpeedX : float = 20;
var SpeedY : float = 20;
// This makes the water more random
var RandomFactor : float = 2;
var Randomizer : float = 1;
private var yVelocity = 0.0;
// The Mesh
private var mesh : Mesh;
// The Base Vertices of the Mesh
private var BaseHeight : Vector3[];
private var vertices: Vector3[];
function Update()
{
// change offset
offset += Speed;
//This Variable is to make the waves more random
Randomizer = Mathf.SmoothDamp(Randomizer,Random.value*RandomFactor,yVelocity,10/RandomFactor);
// Move the Mesh Up and Down
for (var i = 0; i < vertices.Length; i++)
{
//vertices[i].y = Mathf.Sin((offset+vertices[i].x+vertices[i].z)*Speed+offset*Bonus)/Smooth;
vertices[i].y = Mathf.Sin( (offset+vertices[i].x*Randomizer) *SpeedX + (offset+vertices[i].z*Randomizer) *SpeedY )/ Smooth*Randomizer;
vertices[i].y += BaseHeight[i].y;
}
// Attach the new vertices to the mesh
mesh.vertices = vertices;
mesh.RecalculateBounds();
}
But how can I make the water react to a contact, I tried some things with my normal function but can't get a good effect.
I'm happy about every idea you have for this.
Comment
Your answer
Follow this Question
Related Questions
Wave formula(s) (math) 1 Answer
How do I simulate a tsunami wave? 6 Answers
mathf.sin((Mathf.PI / 180) * 180) get 0.8966.. 2 Answers
Different wave speeds 1 Answer
radiusX and radiusY ? 1 Answer