Wave Speed

In this script where I create waves, I am updating the waves. My goal is to keep the player’s ship fixed at the x and z coordinates and determine the direction and speed of the waves relative to the ship. In this part of the script, the speed factor changes the wave speed, but when I increase the speed, the waves first move forward and then accelerate. Then, when I decrease the speed, the waves move backward and slow down. I only want to change the speed of the waves, but I can’t figure out how to do it. Could you help me?

Video link: Waves.mp4 - Google Drive

void UpdateChunkMesh(GameObject chunk)
{
    var meshFilter = chunk.GetComponent<MeshFilter>();
    if (meshFilter == null) return;

    var mesh = meshFilter.mesh;
    var verts = mesh.vertices;

    for (int i = 0; i < verts.Length; i++)
    {
        var vertex = verts[i];
        float y = 0f;

        // Apply wave calculation
        for (int o = 0; o < Octaves.Length; o++)
        {
            if (Octaves[o].alternate)
            {
                var perl = Mathf.PerlinNoise((vertex.x * Octaves[o].scale.x) / Dimension, (vertex.z * Octaves[o].scale.y) / Dimension) * Mathf.PI * 2f;
                y += Mathf.Cos(perl + Octaves[o].speed.magnitude * Time.time) * Octaves[o].height;
            }
            else
            {
                var perl = Mathf.PerlinNoise((vertex.x * Octaves[o].scale.x + Time.time * Octaves[o].speed.x) / Dimension, (vertex.z * Octaves[o].scale.y + Time.time * Octaves[o].speed.y) / Dimension) - 0.5f;
                y += perl * Octaves[o].height;
            }
        }

        verts[i] = new Vector3(vertex.x, y, vertex.z);
    }

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

[Serializable]
public struct Octave
{
    public Vector2 speed;
    public Vector2 scale;
    public float height;
    public bool alternate;
} 

You should add a

float Speed

variable to your code and multiply Speed by Octaves[0].speed. You will then apply this vector to your calculations. If you want to change the wave speed, you should change the Speed value.

If I multiply the speed float by Octaves[0].speed, it will still affect Octaves[0].speed. This would give me the same result as what I did in the inspector

I have looked at the video you posted, I do not see it go backwards. BUT let us say in an example scenario I ask you to count to 10, you go 1,2 etc. then halfway through I ask you to count backwards, you dont count from 10, 9, you would start from where you left off.

With this in mind, dont ask a number to add a minus, negate the original so it counts forwards.

10 + 1 is 11 (obviously)
so why say 10 - 1, its going to go backwards
instead say this
-10 + 1, it is still going forwards because you are working to 0

so if we fabricate variables
0 being your fixed point (fp)

fp + valueToIncrease(1) = 1;
so then fp += valueToIncrease makes fp 1,
make it then fp -= valueToIncrease makes it go backwards from 1 to 0 (so reverse motion)
instead do this
-fp += valueToIncrease (this makes fp equal to -1) and -1 added to 1 makes zero so still moving forwards…

In short negate the first value do not subtract