# Get plain coordinates for another object

Hello everyone,

I have a very interesting question that is boggling my mind. (I can’t find reference or a book about this)

Gameobject aka “Ship” is on the plain mesh “water” and waves come in that move the position/rotation of the ship to look ‘realistic’.

Problem:
I’m using “water” mesh filter changes shape and does not impact x,y,z. I’m using Mathf.Sin in a loop with baseheight to get new values for mesh.RecalculateNormals() that creates the wave like motion.
How can I get the coordinates of the baseHeight and tell my ship it needs to raise or lower on the “water” plane?
//wave script
Mesh mesh = GetComponent().mesh;
if (baseHeight == null)
baseHeight = mesh.vertices;
vertices = new Vector3[baseHeight.Length];

for (int i = 0; i < vertices.Length; i++)
{
Vector3 vertex = baseHeight*;*
vertex.y += Mathf.Sin(Time.time * speed + baseHeight.x + baseHeight.y + baseHeight_.z) * scale;_

vertices = vertex;
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
[113538-mesh-to-boat-error.png|113538]

Use a RayCast from the ships position downward.

Then you can use in built functions for RayCastHit object to find the normal which I think is

``````  Vector3 normal = hit.normal;
``````

This is the closest I could get with my current understanding. This is part of the script to create float on a ship object.

foreach(Vector3 ocean_verts in sealevel.GetComponent().vertices)
{

``````          if (transform.position.x < ocean_verts.x && transform.position.z < ocean_verts.z)
{
transform.position = new Vector3(transform.position.x, ocean_verts.y + 0.2f * Time.deltaTime, transform.position.z);
transform.rotation = Quaternion.Euler(-ocean_verts.y * Time.deltaTime, transform.localEulerAngles.y, ocean_verts.y * Time.fixedDeltaTime * sealevel.GetComponent<my_ocean>().scale * 360);
//transform.Rotate(-ocean_verts.y * Time.deltaTime, transform.localRotation.y, ocean_verts.z * Time.deltaTime);
}

if (transform.position.x < ocean_verts.x && transform.position.z > ocean_verts.z)
{
transform.position = new Vector3(transform.position.x, ocean_verts.y + 0.2f * Time.deltaTime, transform.position.z);
transform.rotation = Quaternion.Euler(-ocean_verts.y * Time.deltaTime, transform.localEulerAngles.y, ocean_verts.y * Time.fixedDeltaTime * sealevel.GetComponent<my_ocean>().scale * 360);
//transform.Rotate(-ocean_verts.y * Time.deltaTime, transform.localRotation.y, ocean_verts.z * Time.deltaTime);
}

if (transform.position.x > ocean_verts.x && transform.position.z > ocean_verts.z)
{
transform.position = new Vector3(transform.position.x, ocean_verts.y + 0.2f * Time.deltaTime, transform.position.z);
transform.rotation = Quaternion.Euler(-ocean_verts.y * Time.deltaTime, transform.localEulerAngles.y, ocean_verts.y * Time.fixedDeltaTime * sealevel.GetComponent<my_ocean>().scale * 360);
//transform.Rotate(-ocean_verts.y * Time.deltaTime, transform.localRotation.y, ocean_verts.z * Time.deltaTime);
}

if (transform.position.x > ocean_verts.x && transform.position.z < ocean_verts.z)
{
transform.position = new Vector3(transform.position.x, ocean_verts.y + 0.2f * Time.deltaTime, transform.position.z);
transform.rotation = Quaternion.Euler(-ocean_verts.y * Time.deltaTime, transform.localEulerAngles.y, ocean_verts.y * Time.fixedDeltaTime * sealevel.GetComponent<my_ocean>().scale * 360);
//transform.Rotate(-ocean_verts.y * Time.deltaTime, transform.localRotation.y, ocean_verts.z * Time.deltaTime);
}
}
``````