0
\$\begingroup\$

I have some issues with detecting the collision when OnTrigger2d, as you can see in my screenshot below, that actually too far from the object.

this is my rigidbody setting

enter image description here

this my script

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Obstacle")
        {
            anim.SetBool("isDeath", true);

            _GameManager.instance.GameOver();
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.tag == "Obstacle")
        {
            anim.SetBool("isDeath", false);

        }
    }
```
\$\endgroup\$
3
  • \$\begingroup\$ Consider using a box collider. Polygon collider are not offering that much more but are taking way more computing power. And it does not even looks like it covers your dino correctly. You can as well use 2 box colliders on the dino if you feel like the head should deserve its own for narrow dodges on the feet. \$\endgroup\$
    – Zibelas
    Feb 11, 2021 at 9:09
  • \$\begingroup\$ From the inspector it looks both the dino and the cacti is selected. \$\endgroup\$
    – Zibelas
    Feb 11, 2021 at 10:24
  • \$\begingroup\$ I would approach this problem by setting a Visual Studio debugger breakpoint in the OnTriggerEnter2D method, wait for it to trigger and then take a look at the local variables to find out what exactly collides with what and where. Can you do that? \$\endgroup\$
    – Philipp
    Feb 11, 2021 at 13:33

0

You must log in to answer this question.

Browse other questions tagged .