So I have this terrain with a perpendicular plane setup, now I want to move the vertices of the plane to their closest resp. vertices on the terrain. I made a drawing to illustrate my thoughts. Final result being the terrain will look like it has some thickness.
i also need the projection of the point on the terrain
I found this code on a previous thread :
float distance = PointToPlaneDistance(smallObj.transform.position, wall.transform.position, wallNormal);
private float PointToPlaneDistance(Vector3 pointPosition, Vector3 planePosition, Vector3 planeNormal)
{
float sb, sn, sd;
sn = -Vector3.Dot(planeNormal, (pointPosition - planePosition));
sd = Vector3.Dot(planeNormal, planeNormal);
sb = sn / sd;
Vector3 result = pointPosition + sb * planeNormal;
return Vector3.Distance(pointPosition, result);
}
The result vector here is the closest point
But what is the plane normal?
Unity has a built in mesh.normals
which gives all the surface normals for the terrain. Which one should I use here?