Example #1
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (!influences)
        {
            return;
        }

        GravityObject obj = collision.gameObject.GetComponent <GravityObject>();

        if (obj)
        {
            if (obj.isInfluenced)
            {
                Vector2 v     = transform.position - obj.gameObject.transform.position;
                float   force = InitRadius / Mathf.Pow(v.magnitude, 2f);

                float mass;
                if (rb)
                {
                    mass = rb.mass;
                }
                else
                {
                    mass = noRigidBodyMass;
                }
                obj.ApplyGravity(v.normalized * force * mass);
            }
        }
    }