Zwiebel
Zwiebel

Reputation: 1615

How to ignore colliding on an object in Unity (2D)

I have 5 objects in my game and 2 "frames". I would like 1 of the objects to collide with the inner frame, but not the 4 another one. I have attached box collider to the frames, and circle colliders to the 5 objects. My problem is that I don't want the 4 objects to collide with the inner frame just with the outer one. Is there a solution for my problem?

Upvotes: 1

Views: 4401

Answers (3)

André Peregrina
André Peregrina

Reputation: 313

For those having this problem, It appears to be that if your parent has a RidgidBody any child collider will trigger the collision.

I solved this by adding a RidgidBody to my child, this avoids the inheritance from the parent.

Upvotes: 0

The Zetsumei
The Zetsumei

Reputation: 49

For anyone who couldn't find a solution for this problem: If your child object's collider is a trigger and your parent object's collider is not, then you can check the collisions in the OnCollisionEnter method. If you still want to do something with other collider, then you can do it in the OnTriggerEnter method. That seperates two colliders into two different functions. This helped me because my child object was a trigger, I hope this solution helps others.

Upvotes: 1

Andrea
Andrea

Reputation: 6123

This is the page, from the official guide, that explains how to use the Collision Matrix. This is the right way to approach your problem: https://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

Basically, you go under Edit->Project Settings->Physics, and you define the rules for the layers' collision. Then, you just need to assign a layer to each object.

Upvotes: 0

Related Questions