Object with several colliders

Imagine that Object A has two different colliders X and Y.

How can I make that collider X interacts with another Object B but that collider Y doesnt interact with Object B?

Depends on what you want to do. Let’s say Object A is your player and your player has a collider β€œX” but he also has another collider for his weapon collider β€œY”. You want the player you take damage when collider X is hit but not when collider Y is hit.

On your weapon, add a script and OnTriggerEnter2D or OnCollisionEnter2D you set if Object B hits damage = 0; Which if you have a set damage, lets say Object B deals 35 damage. Then you set + 35 so that no damage was dealt.

Being more specific, my Object A is my player and has a box collider and a circle collider. I want the box collider to collide with platforms only and i want my circle collider to collide with enemies only.

So my player consists of only one object, not two (like in your example, if I understand it correctly, where my player has two objects: the player itself and his weapon).

Ok, I solved it: On your Object A, you create a child object in which you put the second collider. Then you set different layers for the parent and child objects. Finally you adjust the collision matrix (project settings, physics) to determine what collides with what.

1 Like