current_vertices[current_index].y+=(current_buffer[i]*1.0f/splash_force)*wave_height;//This is what raises the current "tile"'s Y value by the splash force times the maximum height of the wave
}
}
mesh.vertices=current_vertices;
mesh.vertices=current_vertices;//Updates the mesh! :)
GetComponent<MeshFilter>().mesh=mesh;
GetComponent<MeshFilter>().mesh=mesh;//Updates it to unity
// swap buffers
}
}
voidsplash()
voidsplash()
{
{
if(Input.GetKeyDown(KeyCode.Space))
if(Input.GetKeyDown(KeyCode.Space))//Will change for microphone output
{
{
RaycastHithit;
/* Ray cast function to set the splash position */
Vector3down=PlayerSettings.instance.player.transform.TransformDirection(Vector3.down);//Create a raycast from the player's position downwards
if(Physics.Raycast(PlayerSettings.instance.player.transform.position,down,outhit))// Draws a ray dowards from the player and stores the impact location
floatxCoord=(bounds.max.x-bounds.min.x)-((bounds.max.x-bounds.min.x)*hit.textureCoord.x);//Sets the X coordinates for the splash
floatcolumn=(xCoord/xStep);// + 0.5;
floatzCoord=(bounds.max.z-bounds.min.z)-((bounds.max.z-bounds.min.z)*hit.textureCoord.y);//Sets the Y coordinates for the splash
floatrow=(zCoord/zStep);// + 0.5;
floatcolumn=(xCoord/* / xStep*/);
splashAtPoint((int)column,(int)row);
floatrow=(zCoord/* / zStep*/);
splashAtPoint((int)column,(int)row);//Generates the splash!
}
}
}
}
}
}
//THE CODE THAT MAKES THE WAVE MOVE AND FADE OUT
//From Ben Britten's code
voidripple_effect(int[]source,int[]dest)
voidripple_effect(int[]source,int[]dest)
{
{
intx=0;
intx=0;
...
@@ -150,13 +155,9 @@ public class RippleEffect : MonoBehaviour
...
@@ -150,13 +155,9 @@ public class RippleEffect : MonoBehaviour
for(x=1;x<cols;x++)
for(x=1;x<cols;x++)
{
{
position=(y*(cols+1))+x;
position=(y*(cols+1))+x;
dest[position]=(((source[position-1]+
dest[position]=(((source[position-1]+source[position+1]+source[position-(cols+1)]+source[position+(cols+1)])>>1)-dest[position]);//Makes the wave move forward
source[position+1]+
dest[position]=(int)(dest[position]*dampner);//Makes the wave fade out