Esempio n. 1
0
        /// <summary>
        /// Performs a CapsuleCast from a specified collider at an offset position in a direction.
        /// Outputs a RaycastHit.
        /// Returns a bool that is true if something was hit.
        /// </summary>
        /// <param name="collider">Collider to model CapsuleCast from.</param>
        /// <param name="offset">Offset position to apply to collider position for CapsuleCast.</param>
        /// <param name="direction">Direction of CapsuleCast.</param>
        /// <param name="layerMask">Layers to hit.</param>
        /// <param name="hit">Outputted RaycastHit struct.</param>
        /// <param name="invertLayerMask">If true, invert layer mask. Otherwise, use layer mask as normal.</param>
        /// <returns>Returns true if the CapsuleCast hit something. Otherwise, returns false. When false, outputted hit is null.</returns>
        public static bool CapsuleCast(
            CapsuleCollider collider,
            Vector3 offset,
            Vector3 direction,
            LayerMask layerMask,
            out RaycastHit hit,
            bool invertLayerMask = false
            )
        {
            Vector3 capStart, capEnd;

            CalculateCapsuleCaps(collider, collider.transform.position + offset, collider.transform.rotation, out capStart, out capEnd);
            return(UPhysics.CapsuleCast(
                       capStart,
                       capEnd,
                       collider.radius,
                       direction.normalized,
                       out hit,
                       direction.magnitude,
                       invertLayerMask ? ~layerMask.value : layerMask.value
                       ));
        }