- Home /
2D colliders don't appear to be detecting each other
Alright, so I've got two game objects with 2D box colliders (one player-controlled and one unmoving) seem to be refusing to detect each other. I've got a script to destroy the unmoving object when the two come into contact:
using UnityEngine;
using System.Collections;
public class DestroyOnContact : MonoBehaviour
{
void OnTriggerEnter2D (Collider2D other)
{
Destroy (gameObject);
}
}
I've tried colliding them with Is Trigger turned on for both objects' colliders, I've tried turning off Is Trigger and using OnColliderEnter2D, and I've even tried just using OnTriggerEnter/OnColliderEnter without the 2D bit. They just refuse to interact with each other at all. I'm probably missing something simple, but I can't think of any possibilities that I haven't tried. Oh, and they are on the same layer, in case that's relevant/important. And at the same Z position, though from what I understand that shouldn't matter.
Can you take a screenshot of the inspector please, i think i might know what's up
It appears you have a collider on the object and then another on a child object(let me know if I'm wrong). Is there a chance that either the child object hasn't got a rigid body or that the child object is the object being destroyed leaving just the parent object and with it the image of the wolf.
Nope, the only child object involved is a camera. No colliders or rigidbodies there.
I actually sort of figured it out; for some reason I have to turn off Is $$anonymous$$inematic for both objects (which of course also requires setting gravity scale to 0 so they don't fall off the screen). Now, though, I've got another problem: the colliders appear to have padding around them, reacting to each other before they actually touch. Not sure what to make of that.
Answer by hamcav · Mar 12, 2014 at 12:58 PM
From Unity Script Reference:
"Note that trigger events are only sent if one of the colliders also has a rigidbody attached."
So you need at least one rigidbody attached to one of you gameobjects. That should fix your Problem :D
Unfortunately not. Sorry, forgot to mention, but both objects have rigidbody2Ds attached, and I tried it with only one having a rigidbody2D and, when that failed, with just regular rigidbodies. None of it worked.
Your answer
![](https://koobas.hobune.stream/wayback/20220613140034im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
overlapsphere to destroy NPCs on exit 1 Answer
Is there a way to deny an exit (and therefore OnTriggerExit) 2 Answers
Collider/trigger collision causing physics glitch 0 Answers
Box Collider (Trigger) Efficiency Question 0 Answers
Collider Lifts me off Ground ??? And I'm afraid of heights !!! 1 Answer