我有一个地形和垂直平面设置,现在我想将这两个意思合并起来,将平面的顶点移动到它们在地形上最近的顶点。
我画了一个图来说明我的想法。最终结果是地形看起来像有一定厚度。
我还需要将点投影到地形上。
我在以前的帖子中找到了这段代码:
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(i think!) 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?