Home Unity

Compare position of 2 gameobjects

Hey I was wondering if anybody can help I am trying to find a way to compare the position of 2 rigidbodys and when one object is directly above the other destroy the one underneath. I could use hitboxes but with having multiple instantiated objects I think comparing the positions may be the better way to go.

Replies

  • Farfarer
    Offline / Send Message
    Farfarer polycounter lvl 17
    Something like this?
    1. float tolerance = 0.01;
    2. if (
    3. (Mathf.Abs(lowerTransform.position.x - upperTransform.position.x) < tolerance) &&
    4. (Mathf.Abs(lowerTransform.position.z - upperTransform.position.z) < tolerance)
    5. ) {
    6. Destroy(lowerTransform.gameObject);
    7. }
Sign In or Register to comment.