private RayCastOutputData GetClosestRayCastResult(FRay ray, List <BoundBase> collidedBounds) { float resultShortestDistance = -1.0f; BoundBase resultBound = null; // DO RAY CAST IN ALL COLLIDED BOUNDING BOXES for (Int32 i = 0; i < collidedBounds.Count; i++) { float localIntersectionDistance = 0.0f; BoundBase.BoundType boundType = collidedBounds[i].GetBoundType(); if ((boundType & BoundBase.BoundType.AABB) == BoundBase.BoundType.AABB) { localIntersectionDistance = GeometryMath.Intersection_RayAABB(ray, collidedBounds[i] as AABB); } else if ((boundType & BoundBase.BoundType.OBB) == BoundBase.BoundType.OBB) { localIntersectionDistance = GeometryMath.Intersection_RayOBB(ray, collidedBounds[i] as OBB); } if (resultShortestDistance <= -1.0f || (localIntersectionDistance > 0.0f && localIntersectionDistance < resultShortestDistance)) { resultShortestDistance = localIntersectionDistance; resultBound = collidedBounds[i]; } } Vector3 intersectionPosition = ray.GetPositionInTime(resultShortestDistance); return(new RayCastOutputData(ray, resultBound, resultShortestDistance, intersectionPosition)); }