视觉辅助
厚度VS宽度:here如何确定厚度与宽度? (使用光线投射)
请查看GIF短。
这里的厚度不同于宽度,因为有多个壁,因为有外部和内部圆柱体。厚度是圆柱体任何一侧的外壁/内壁之间的距离的测量值,其中厚度是从一端到另一端的距离,其中包括两者之间的中空空间。
上的GIF快速概要提供
-On每次点击原点(蓝色)和目的地点被创建(橙色)球体来表示,其中用户点击和用于计算距离的解释结束点(显示在GUI上)。
原点定义了用户在对象对象的表面上单击的位置,并且目标定义了与原点的世界Y轴垂直的点,其中第二条射线朝向第一条射线投射,击中另一边对撞机。
电流:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//obtain the vector where the ray hit the collider.
hitPoint = hit.point; //origin point
//offset the ray, keeping it along the XZ plane of the hit
Vector3 offsetDirection = -1 * hit.normal;
//offset a long way, minimum thickness of the object
ray.origin = hit.point + offsetDirection * 100;
//point the ray back at the first hit point
ray.direction = (hit.point - ray.origin).normalized;
//raycast all, because there might be other objects in the way
RaycastHit[] hits = Physics.RaycastAll(ray);
foreach (RaycastHit h in hits)
{
if (h.collider == hit.collider)
{
hitBack = h.point; //destination point
}
}
}
目前,宽度是到位的功能。我想计算厚度而不必进入物体内部(如在gif中看到的那样)。
惊人参考
http://answers.unity3d.com/questions/386698/detecting-how-many-times-a-raycast-collides-with-a.html
这家伙基本上有同样的问题我和有一个解决方案能够工作。我不确定Linecasting如何与Raycasting相互作用。
让我们[在聊天中继续讨论](http://chat.stackoverflow.com/rooms/151438/discussion-between-ryemoss-and-jtth)。 – ryeMoss