|
|
|
|
|
|
/// </summary>
|
|
|
|
public class RayPerception3D : RayPerception |
|
|
|
{ |
|
|
|
Vector3 m_EndPosition; |
|
|
|
RaycastHit m_Hit; |
|
|
|
float[] m_SubList; |
|
|
|
|
|
|
|
|
|
|
// along with object distance.
|
|
|
|
foreach (var angle in rayAngles) |
|
|
|
{ |
|
|
|
m_EndPosition = transform.TransformDirection( |
|
|
|
PolarToCartesian(rayDistance, angle)); |
|
|
|
m_EndPosition.y = endOffset; |
|
|
|
Vector3 startPositionLocal = new Vector3(0, startOffset, 0); |
|
|
|
Vector3 endPositionLocal = PolarToCartesian(rayDistance, angle); |
|
|
|
endPositionLocal.y += endOffset; |
|
|
|
|
|
|
|
var startPositionWorld = transform.TransformPoint(startPositionLocal); |
|
|
|
var endPositionWorld = transform.TransformPoint(endPositionLocal); |
|
|
|
|
|
|
|
var rayDirection = endPositionWorld - startPositionWorld; |
|
|
|
Debug.DrawRay(transform.position + new Vector3(0f, startOffset, 0f), |
|
|
|
m_EndPosition, Color.black, 0.01f, true); |
|
|
|
Debug.DrawRay(startPositionWorld,rayDirection, Color.black, 0.01f, true); |
|
|
|
if (Physics.SphereCast(transform.position + |
|
|
|
new Vector3(0f, startOffset, 0f), 0.5f, |
|
|
|
m_EndPosition, out m_Hit, rayDistance)) |
|
|
|
if (Physics.SphereCast(startPositionWorld, 0.5f, rayDirection, out m_Hit, rayDistance)) |
|
|
|
{ |
|
|
|
for (var i = 0; i < detectableObjects.Length; i++) |
|
|
|
{ |
|
|
|