0
\$\begingroup\$

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();
    }
}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Jul 11, 2021 at 15:12
  • \$\begingroup\$ 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. \$\endgroup\$
    – GospelBG
    Jul 11, 2021 at 15:21
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Jul 11, 2021 at 15:23
  • \$\begingroup\$ Oh, ok, I created a new question. Thanks for all the help given until now. \$\endgroup\$
    – GospelBG
    Jul 11, 2021 at 16:16

0

You must log in to answer this question.

Browse other questions tagged .