public override int CapsuleCast(out HitInfo hitInfo, Vector3 bottom, Vector3 top, float radius, Vector3 castDisplacement, LayerMask layerMask, float minimumDistance = 0f, bool ignoreTrigger = true) { Vector3 bottomToTop = top - bottom; Vector3 center = bottom + 0.5f * bottomToTop.magnitude * bottomToTop.normalized; Vector2 size = new Vector2(2f * radius, bottomToTop.magnitude + 2f * radius); float castAngle = Vector2.SignedAngle(bottomToTop.normalized, Vector2.up); bool previousQueriesHitTriggers = Physics2D.queriesHitTriggers; Physics2D.queriesHitTriggers = !ignoreTrigger; hits = Physics2D.CapsuleCastNonAlloc( center, size, CapsuleDirection2D.Vertical, castAngle, castDisplacement.normalized, raycastHits, castDisplacement.magnitude, layerMask ); Physics2D.queriesHitTriggers = previousQueriesHitTriggers; GetClosestHit(out hitInfo, castDisplacement, minimumDistance, layerMask); return(hits); }
public static int CapsuleCast(Vector3 bottom, Vector3 top, float radius, Vector3 castDisplacement, LayerMask layerMask, RaycastHit2D[] raycastHits, bool ignoreTrigger = true) { Vector3 bottomToTop = top - bottom; Vector3 center = bottom + 0.5f * bottomToTop.magnitude * bottomToTop.normalized; Vector2 size = new Vector2(2f * radius, bottomToTop.magnitude + 2f * radius); float castAngle = Vector2.SignedAngle(bottomToTop.normalized, Vector2.up); Physics2D.queriesHitTriggers = !ignoreTrigger; int hits = Physics2D.CapsuleCastNonAlloc( center, size, CapsuleDirection2D.Vertical, castAngle, castDisplacement.normalized, raycastHits, castDisplacement.magnitude, layerMask ); return(hits); }