- Home /
How to not trigger its own collision box?
Why does this print the collision box that the code is on and the one that's not?
function OnTriggerEnter (col : Collider)
{
if(!col.transform.IsChildOf(transform.parent.parent))
{
Debug.Log (col.gameObject.name + col.gameObject.tag);
}
}
Question..... I need it to only regester the Box Collider it hits and not itself.
probably dont want transform.parent.parent you want transform.root to find the root parent.
It must be triggering itself. Your code is correct your input must be wrong to produce that output.
whats this attached to?
I have an empty that has the movement script which uses
transform.position.y = transform.position.y + 1;
due to the fact I need to move ONLY 1 unit each time with no physics.
in the empty I have a Cube Object with six colliders as the side's. The Collider's have my ontriggerenter function and they have rigidbodys.
maybe one side of the collider is colliding with the other side?
anyways dont use 6 colliders thats just silly.
use 1, I know you'd like to know which side was hit.
Take the normal of the side that was hit and compare it against transform.up, -transform.up,transform.right,-transform.right,transform.forward and -transform.forward to deter$$anonymous$$e which side was hit.
Bottom line:
you are mistaken...
I have just tested this, by tagging the parent (in a similar set-up) one thing, and the child (collider) a different tag. BOTH Debugs refer to the collider as expected. Therefore, you must have the SA$$anonymous$$E TAG on the colliding object..
Your answer
![](https://koobas.hobune.stream/wayback/20220613083936im_/https://answers.unity.com/themes/thub/images/avi.jpg)