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
    Options
    Offline / Send Message
    Something like this?
    float tolerance = 0.01;
    if	(
    		(Mathf.Abs(lowerTransform.position.x - upperTransform.position.x) < tolerance) &&
    		(Mathf.Abs(lowerTransform.position.z - upperTransform.position.z) < tolerance)
    	) {
    		Destroy(lowerTransform.gameObject);
    	}
    
Sign In or Register to comment.