我試着計算交點平面和線,但我認爲得到錯誤的結果。 試試這個代碼(從http://wiki.unity3d.com/index.php/3d_Math_functions獲得):如何計算交點平面和線(Unity3d)
public static bool LinePlaneIntersection(out Vector3 intersection, Vector3 linePoint, Vector3 lineVec, Vector3 planeNormal, Vector3 planePoint)
{
float length;
float dotNumerator;
float dotDenominator;
Vector3 vector;
intersection = Vector3.zero;
//calculate the distance between the linePoint and the line-plane intersection point
dotNumerator = Vector3.Dot((planePoint - linePoint), planeNormal);
dotDenominator = Vector3.Dot(lineVec, planeNormal);
if (dotDenominator != 0.0f)
{
length = dotNumerator/dotDenominator;
vector = SetVectorLength(lineVec, length);
intersection = linePoint + vector;
return true;
}
else
return false;
}
如果你爲了學習而去做,那麼繼續。如果你打算在遊戲中使用它,那麼也許你應該在那裏停下來,改用Physics.Raycast/Linecast。 – Everts