need to duplicate a 'waves' plane to make an ocean

Hi
my final goal, in short, is a top-down view game of a boat sailing across an ocean.
i found a very nice script from a different thread here that, when attached to a plane, animates the mesh to have a waves effect.
im trying to create a seamless ocean using this script, if possible.
simply duplicating it wont work because the waves animation do not match at the edges, and scaling it also scales the the size of the waves.
this is for learning purposes, so i might be way off in my way of thinking about this, if so, i would appreciate a nudge in the right direction.

thats the script

using UnityEngine;
using System.Collections;

public class SurfaceWaves : MonoBehaviour
{
    public float scale = 0.1f;
    public float speed = 1.0f;
    public float noiseStrength = 1f;
    public float noiseWalk = 1f;
   
    private Vector3[] baseHeight;
   
    void Update () {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
       
        if (baseHeight == null)
            baseHeight = mesh.vertices;
       
        Vector3[] vertices = new Vector3[baseHeight.Length];
        for (int i=0;i<vertices.Length;i++)
        {
            Vector3 vertex = baseHeight[i];
            vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].x + baseHeight[i].y + baseHeight[i].z) * scale;
            vertex.y += Mathf.PerlinNoise(baseHeight[i].x + noiseWalk, baseHeight[i].y + Mathf.Sin(Time.time * 0.1f)    ) * noiseStrength;
            vertices[i] = vertex;
        }
        mesh.vertices = vertices;
        mesh.RecalculateNormals();
    }
}

I just tried it and it works if you rotate and scale. And by scale I mean, if you have a series of planes you might need to change the Z axis from 1 to -1 and you might need to rotate on the Y axis by 180 degrees. This will depend on the placement of the planes. I use 4 cubes and I was able to get them all in sync by just negating the scale from 1 to -1 on the Z axis and rotating 2 cubes along the diagonal by 180 degrees on the Y axis. Hope this helps.

I would recommend to do this in a vertex shader. Otherwise the performance will be really bad when you have a big ocean.

that helped, thank you, for some reason i couldn’t get it to match although i tried similar logic.
unfortunately that is not what i was hoping for, even though the edges are synched, its obvious one plane is just a mirror image of the other one, it becomes more apparent when combined with a material of some kind, i believe that this is not the correct way to go about it, even if it was working as id hoped the performance would probably be an issue as sz Bit Barons suggested.

would this help with the problems i mentioned above?

what are the common ways of achieving somthing like that? not necessarily using that script.

The way to go with a shader would be:

  • Create a plane with many subdivisions
  • write a unity compatible shader which moves the vertices up and down over time 8very much like your script)
  • apply that shader to the plane

pro:

  • It is much faster cause the vertices are moved at the same time, not one after another
  • less mess in the scene hierachy

cons:

  • not usable for collision - if you want floating objects moving up and down with the waves you need to run an algorithm which works the same way as the shader (with the same values). This can be tricky and will likely lead to mistakes.