public List <GameObject> GetCurrentOverlapping()
 {
     return(PhysicsExtensions.OverlapCapsule(Capsule)
            .Select(x => x.gameObject)
            .Where(x => x != currentCollider && x != rootCollider)
            .ToList());
 }
 public bool OverlapsWithTags(string[] tagsToCheck)
 {
     return(PhysicsExtensions.OverlapCapsule(Capsule)
            .Where(x => x != currentCollider && x != rootCollider)
            .ToList()
            .Any(collider => tagsToCheck.Any(tag => tag == collider.tag)));
 }
        private void DetectCollisions()
        {
            var colliders = PhysicsExtensions.OverlapCapsule(this.Collider, this.CollisionLayerMask, QueryTriggerInteraction.Ignore);

            if (colliders.Length > 0)
            {
                var velMag = mCurrentVelocity.sqrMagnitude * this.Mass * this.CollisionAppliedMassRatio;

                for (var i = 0; i < colliders.Length; ++i)
                {
                    var c = colliders[i];
                    if (this.Collider != c)
                    {
                        HandleCollision(c, velMag);
                    }
                }

                this.IsFalling = !this.Sensors.GroundSensors.HasCollidedWithGround();
                if (!this.IsFalling)
                {
                    mCurrentVelocity.y = 0f;
                }
            }
            else
            {
                this.IsFalling = true;
            }
        }
Exemplo n.º 4
0
    public static bool isObjectColliding(
        GameObject go,
        List <GameObject> ignoreGameObjects = null,
        float expandBy = 0.0f,
        bool useBoundingBoxInChecks = false
        )
    {
        if (ignoreGameObjects == null)
        {
            ignoreGameObjects = new List <GameObject>();
        }
        ignoreGameObjects.Add(go);
        HashSet <Collider> ignoreColliders = new HashSet <Collider>();

        foreach (GameObject toIgnoreGo in ignoreGameObjects)
        {
            foreach (Collider c in toIgnoreGo.GetComponentsInChildren <Collider>())
            {
                ignoreColliders.Add(c);
            }
        }

        int layerMask = 1 << 8 | 1 << 10;

        foreach (CapsuleCollider cc in go.GetComponentsInChildren <CapsuleCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapCapsule(cc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        foreach (BoxCollider bc in go.GetComponentsInChildren <BoxCollider>())
        {
            if ("BoundingBox" == bc.gameObject.name && (!useBoundingBoxInChecks))
            {
                continue;
            }
            foreach (Collider c in PhysicsExtensions.OverlapBox(bc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        foreach (SphereCollider sc in go.GetComponentsInChildren <SphereCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapSphere(sc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Exemplo n.º 5
0
    public static Collider[] collidersObjectCollidingWith(GameObject go, List <GameObject> ignoreGameObjects = null, float expandBy = 0.0f)
    {
        if (ignoreGameObjects == null)
        {
            ignoreGameObjects = new List <GameObject>();
        }
        ignoreGameObjects.Add(go);
        HashSet <Collider> ignoreColliders = new HashSet <Collider>();

        foreach (GameObject toIgnoreGo in ignoreGameObjects)
        {
            foreach (Collider c in toIgnoreGo.GetComponentsInChildren <Collider>())
            {
                ignoreColliders.Add(c);
            }
        }

        HashSet <Collider> collidersSet = new HashSet <Collider>();
        int layerMask = 1 << 8 | 1 << 10;

        foreach (CapsuleCollider cc in go.GetComponentsInChildren <CapsuleCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapCapsule(cc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        foreach (BoxCollider bc in go.GetComponentsInChildren <BoxCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapBox(bc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        foreach (SphereCollider sc in go.GetComponentsInChildren <SphereCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapSphere(sc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        return(collidersSet.ToArray());
    }