//[System.Obsolete ("Does not work well, will only return an object a single time")] /** Returns all hits when checking height for \a position. * \note Does not work well with thick raycast, will only return an object a single time */ public RaycastHit[] CheckHeightAll(Vector3 position) { RaycastHit[] hits; if (!heightCheck) { RaycastHit hit = new RaycastHit(); hit.point = position; hit.distance = 0; return(new RaycastHit[1] { hit }); } if (thickRaycast) { Ray ray = new Ray(position + up * fromHeight, -up); hits = Physics.SphereCastAll(ray, finalRaycastRadius, fromHeight, heightMask); for (int i = 0; i < hits.Length; i++) { hits[i].point = Mathfx.NearestPoint(ray.origin, ray.origin + ray.direction, hits[i].point); //position+up*(fromHeight-hit.distance); } } else { hits = Physics.RaycastAll(position + up * fromHeight, -up, fromHeight, heightMask); } return(hits); }
/** Same as #CheckHeight, except that the raycast will always start exactly at \a origin * \a walkable will be set to false if nothing was hit. The ray will check a tiny bit further than to the grids base to avoid floating point errors when the ground is exactly at the base of the grid */ public Vector3 Raycast(Vector3 origin, out RaycastHit hit, out bool walkable) { walkable = true; if (!heightCheck) { hit = new RaycastHit(); return(origin - up * fromHeight); } if (thickRaycast) { Ray ray = new Ray(origin, -up); if (Physics.SphereCast(ray, finalRaycastRadius, out hit, fromHeight + 0.005F, heightMask)) { return(Mathfx.NearestPoint(ray.origin, ray.origin + ray.direction, hit.point)); //position+up*(fromHeight-hit.distance); } else { if (unwalkableWhenNoGround) { walkable = false; } } } else { if (Physics.Raycast(origin, -up, out hit, fromHeight + 0.005F, heightMask)) { return(hit.point); } else { if (unwalkableWhenNoGround) { walkable = false; } } } return(origin - up * fromHeight); }