# Unity OnTriggerEnter2D doesen't check Z Axis

I am coding my game's collisions using onTriggerEnter(). The problem is that it only checks X and Y axis and not the Z one, and that is causing me some problems because my game uses the Z axis and I can't use 3D colliders for other reasons.

There is a way to check also the Z axis with onTriggerEnter or a similar function? At this moment my code is:

void OnTriggerEnter2D(Collider2D col)
{
Debug.Log("Collision Detected");
if(col.gameObject.tag == "Safe")
{
return;
}
else if(col.gameObject.tag == "Obstacle")
{
Debug.Log("Changing to Game Over scene");
GameController.GetComponent<SceneController>().gameOver();
}
}

• 2D physics are, by definition, 2D. Only x and y exist as far as the underlying Box2D physics engine is concerned. Can you elaborate on the reasons why you cannot use 3D physics? We may be able to help you work around that issue. Or you could check the z cooridnates inside your OnTriggerEnter2D function and discard triggers that you don't want to count. Jul 11, 2021 at 15:12
• I can't use 3D colliders mainly because there aren't colliders for the shapes I am using. Also, because it bugs a lot for the models I am using. I have seen Physics2D.OverlapCircle, that have minDepth and maxDepth, for detecting objects in a custom Z axis area. Jul 11, 2021 at 15:21
• Sounds like you should ask "How can I create a good physics representation for these models" and show us the kinds of shapes you're working with. I don't think throwing away the z axis is the best solution to that problem. Jul 11, 2021 at 15:23
• Oh, ok, I created a new question. Thanks for all the help given until now. Jul 11, 2021 at 16:16