代码如下:
public bool CalPlaneLineIntersection(Vector3 planeVec, Vector3 planePos, Vector3 lineVec, Vector3 linePos, out Vector3 position)
{
position = Vector3.zero;
float dot = Vector3.Dot(planeVec, lineVec);
if (Mathf.Approximately(dot, 0)) return false;
float t = ((planePos.x - linePos.x) * planeVec.x + (planePos.y - linePos.y) * planeVec.y + (planePos.z - linePos.z) * planeVec.z) / dot;
position = new Vector3(linePos.x + lineVec.x * t, linePos.y + lineVec.y * t, linePos.z + lineVec.z * t);
return true;
}
实测运行正确。