Simple Collider issue

On my character (a ship) i have two colliders, one polygon collider 2D and one circle collider 2D.

The Polygon Collider 2D represents i’ts “body”, so when this collider collides with an obstacle (that uses Edge Colliders 2D) i want the ship to be destroyed.

The Circle Collider 2D is for detecting nearby coins.

My issue is that i don’t know how to remove the Circle Colliders ability to collide with the Edge Collider on the obstacle. Because now when the Circle Collider (that is only there to detect coins) collides with an obstacle it triggers the destroy method on the ship.

75404-example.png

As you can see in left picture above, the ship gets destroyed when its Circle Collider touches the Edge Colliders, which is unwanted. Look at the right picture and you can see how i want the colliders to behave; the Circle Collider should ignore the edge colliders on the orange obstacle where as only the polygon collider triggers the destroy method.

Or more specifically, how can i modify this method (which is attached to the ship):

void OnTriggerEnter2D(Collider2D other)
{
	if (other.tag = "Obstacle") 
	{
		Destroy (this.gameObject);
	}
}

To only trigger when the ships polygon collider enters something, not when any of the ships colliders enters something.

I’d like to add that the Circle/Polygon collider has “is trigger”-option checked while the edge colliders do not have that.

I don’t think you can. You are not supposed to have more than one collider on one object, I think.

Try adding an empty child for your circle collider.

The above is wrong: Trigger events are caused by rigidbodies. Having multiple children with colliders only define a more complex construction which will then be used by the rigidbody to detect collisions. That way you can construct the shape of a weapon for collision using several box colliders in children.

A hacked approach would be to change the polygon collider to IsTrigger = false and use the OnCollisionEnter2D() method for crashes and the OnTriggerEnter2D() for MONEEEEY!!!

Another edit:
You could check if the polygon collider caused the collision by using a second call to the physics in the OnTriggerEnter2D() method:

polyCollider.IsTouching(other);

You can add multiple simple colliders to an object for example a rifle mesh collider would be full of vertices but a few rectangle colliders would work fine.

However getting them to detect collisions seperately you would want to have layers of parent/child. Looks like you guys figured it out :slight_smile: