How to make mesh ripples fade c#

Hi, I am new to coding/this forum and I am using a sin function to produce ripples on a mesh from the position of a game object, which seems to work. However, the ripples never fade away which looks ugly. Here is a copy pasted version of my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class waterscrv2 : MonoBehaviour
{
Mesh mymesh;
float speed = 8f;
public GameObject cube;
private GameObject objects = new GameObject[0];
// Start is called before the first frame update
void Start()
{
objects = GameObject.FindGameObjectsWithTag(“Respawn”);
Debug.Log(objects.Length);
//mymesh = GetComponent().mesh;

    //CreateRipples();
}

// Update is called once per frame
void Update()
{
        //float size = transform.localScale.x/2;
        mymesh = GetComponent<MeshFilter>().mesh;
        var vertices = mymesh.vertices;
        float distanceX1 = (transform.position.x - objects[0].transform.position.x)/mymesh.bounds.size.x;
        float distanceZ1 = (transform.position.z - objects[0].transform.position.z)/mymesh.bounds.size.z;
        float distanceX2 = (transform.position.x - objects[1].transform.position.x)/mymesh.bounds.size.x;
        float distanceZ2 = (transform.position.z - objects[1].transform.position.z)/mymesh.bounds.size.z;

    for (var i = 0; i < vertices.Length; i++)
        {
            float offset = (vertices<em>.x * vertices<em>.x) + (vertices_.z * vertices*.z);*_</em></em>

var ripples1 = Mathf.Sin(Time.time * -speed + (offset + (vertices.x * distanceX1) + (vertices_.z * distanceZ1)) * 4) * .01f;
var ripples2 = Mathf.Sin(Time.time * -speed + (offset + (vertices.x * distanceX2) + (vertices.z * distanceZ2)) * 4) * .01f;
vertices*.y = ripples1;*
}_

mymesh.vertices = vertices;
mymesh.RecalculateNormals();
}
}
Can anyone tell me how to damp the ripples based on the distance from the game object? Sorry if this is hard to read/understand.

Okay, first let me tell you how COOL this thing is. Secondly I’m not a mathematician and I have no idea what your equation is doing, so I dealt with the matter in a very rudimentary way. Here’s the resulting code and the comments should make it self explanatory:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ripples : MonoBehaviour {

	Mesh mymesh; 
	float speed = 8f; 
	public GameObject cube; 
	private GameObject[] objects = new GameObject[0]; 

	float yFactor=1f;
	
	// Start is called before the first frame update 
	void Start() { 
		objects = GameObject.FindGameObjectsWithTag("Respawn"); 
		Debug.Log(objects.Length); //mymesh = GetComponent().mesh;

     //CreateRipples();
 }

 // Update is called once per frame
	void Update()
	{
		//float size = transform.localScale.x/2;
         mymesh = GetComponent<MeshFilter>().mesh;
         var vertices = mymesh.vertices;
         float distanceX1 = (transform.position.x - objects[0].transform.position.x)/mymesh.bounds.size.x;
         float distanceZ1 = (transform.position.z - objects[0].transform.position.z)/mymesh.bounds.size.z;
        //  float distanceX2 = (transform.position.x - objects[1].transform.position.x)/mymesh.bounds.size.x;
        //  float distanceZ2 = (transform.position.z - objects[1].transform.position.z)/mymesh.bounds.size.z;
     
	 	//1, Find furthest vertex distance
		 Vector2 otherObjPos=new Vector2(objects[0].transform.position.x, objects[0].transform.position.z);
		 float furthestDistance=0f;
		 for (int i=0; i<vertices.Length; i++) {
			 float vertexDistance=Vector2.Distance(new Vector2(vertices_.x, vertices*.z), otherObjPos);*_

* if (vertexDistance>furthestDistance)*
* furthestDistance=vertexDistance;*
* }*

* for (var i = 0; i < vertices.Length; i++)*
{
float offset = (vertices.x * vertices.x) + (vertices_.z * vertices*.z);
var ripples1 = Mathf.Sin(Time.time * -speed + (offset + (vertices.x * distanceX1) + (vertices.z * distanceZ1)) * 4) * yFactor;
// var ripples2 = Mathf.Sin(Time.time * -speed + (offset + (vertices.x * distanceX2) + (vertices.z * distanceZ2)) * 4) * .01f;_

_vertices.y = ripples1;*_

* //2. Height should be a function of the relationship between vertex distance and furthest distance*
float vertexDistance=Vector2.Distance(new Vector2(vertices_.x, vertices*.z), otherObjPos);
vertices.y=(furthestDistance-vertexDistance)/furthestDistance;

}_

mymesh.vertices = vertices;
mymesh.RecalculateNormals();
}
}

The efficiency of this is dubious…
Also I’d avise you to move mymesh = GetComponent<MeshFilter>().mesh; from Update to Start.
Also, if you’re looking into incorporating this into a full blown game, I’d advise you not to and to look into animated normal maps or something akin.
Cheers!
EDIT: Come to think of it, you probably want to fade off the ripples based on a radius around your movable object. This is even easier as you don’t need to look for the furthest vertex in your mesh, you just need to use this distance in the second point of the code.
ALSO. In my tests I didn’t bother to get the actual world vertex position. Now that I tested it by turning the rippling plane, I see it doesn’t work well. Vector3 worldVertexPos=transform.TransformPoint(vertices*); float vertexDistance=Vector2.Distance(new Vector2(worldVertexPos.x, worldVertexPos.z), otherObjPos); should work.*