///*** Trigger ***///
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Fragile")
        {
            Vector3 collPoint = other.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position);            // other.contacts[0].point;

            // Breaking Bad
            var fracture = other.gameObject.GetComponent <Fracture>();
            _breaker.Break(fracture, collPoint);
        }
    }
Example #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.relativeVelocity.magnitude < minSpeed)
        {
            return;
        }
        //if(collision.)
        foreach (ContactPoint2D contact in collision.contacts)
        {
            float dotProd = Vector2.Dot(collision.relativeVelocity, contact.normal);
            if (dotProd < 10)
            {
                return;
            }
        }


        float otherMass = 100;

        if (collision.rigidbody)
        {
            otherMass = collision.rigidbody.mass;
        }

        float myMass = 100;

        if (collision.otherRigidbody)
        {
            myMass = collision.otherRigidbody.mass;
        }


        if (otherMass == myMass)
        {
            Breaker otherBreaker = collision.gameObject.GetComponent <Breaker>();
            if (otherBreaker)
            {
                otherBreaker.Break();
            }
        }
        if (myMass <= otherMass)
        {
            Break();
        }
    }