With two box colliders on one object, how can I tell which one was hit?
I'm attempting to make a teleporter system for a 2d game. My plan is to have one gameobject called Teleporter with 2 BoxCollider2D's set as triggers using their offsets to position them on screen.
Then I want to use OnTriggerEnter to detect collisions, and teleport the player to the position of the other collider. The problem is I'm not sure how to figure out which collider was collided with.
When using multiple boxcollider2d's on a single object, is there a way to see which collider was collided with?
Thanks.
would hit.point work? Or do you definitly need to tell the difference between the 2 colliders?
I need to know the difference between them. I want it so that if my dude collides with the collider on the left side of the screen that it moves him to the position of the collider on the right side of the screen and vice versa.
Answer by Owen-Reynolds · Feb 09, 2016 at 04:53 PM
What you're asking for is how OnTriggerEnter works -- it tells you the exact collider that hit it (the 3D version does, anyway,) and fires for each of your subcolliders.
It really has the opposite problem -- if an object is built from 3 colliders, it's hard to make OnTriggerEnter fire only once. It always tells you: hand, arm, body, head ... . OnCollisionEnter is works the other way -- if you hit something it fires once and won't fire if any other parts of you also land.