void applyGravity(Gravable grav1, Gravable grav2) { if (grav1 == grav2) { Debug.Log("whaa"); } Vector2 totalForce1 = new Vector2(0, 0); Vector2 totalForce2 = new Vector2(0, 0); Vector2 myPos = grav1.gameObject.transform.position; Vector2 otherPos = grav2.gameObject.transform.position; float otherMass = grav1.GetComponent <Rigidbody2D> ().mass; float myMass = grav2.GetComponent <Rigidbody2D> ().mass; Vector2 towards = (myPos - otherPos); float r3 = towards.sqrMagnitude * towards.magnitude; float gravMag = (G * otherMass * myMass / r3); totalForce1 += gravMag * -towards; totalForce2 += gravMag * towards; if (grav1.isAffectedByOthers && grav2.affectsOthers) { grav1.GetComponent <Rigidbody2D> ().AddForce(totalForce1); } if (grav2.isAffectedByOthers && grav1.affectsOthers) { grav2.GetComponent <Rigidbody2D> ().AddForce(totalForce2); } }