One character with multiple collider on different layers

Hi guys,

I’m working on a game in which I have a character, ennemies and platforms. I want my character feet to collide with the ground and the platforms, and having his body to collide with ennemies. In order to achieve that I made this very simple set-up :

Character structure:
-Character : contains a RigidBody2D a BoxCollider2D that represent his body
– Feet : contains a BoxCollider2D that represent his feet

Layers
Character GameObject is assign to the “character” layer
Feet GameObject is assign to the “ground” layer
Ground and platforms are assigned to the “ground” layer
Ennemies which are assigned to the “ennemy” layer

Layer Collision Matrix
In the Layer Collision Matrix I have uncheck everything and then check :
“character” with “ennemy”
and
“ground” with “ground”

Result
With this set-up my character body collides with platforms even if their layers are not supposed to collide each other. Any idea why ?

Thanks

Just making sure, you set the Physics2D Collision Matrix, not 3D, correct?

Yep, I set the 2D one :slight_smile:

Well according to your setup that should be working correctly. You are setting the GameObject which has the collider’s layer, and not the Sorting Layer or otherwise? (You specified GameObject, but just to be certain it is the correct GameObject and Layer type).

Are you able to see results of any kind with the layering? Or does everything collide with everything always?

Hi,

I’m trying to create a small scene in order to have the minium of assets and layers required - so far it does not work too :wink: I will dig a bit more, I know it should work, so it has to be my fault !

Thx

A good operating philosophy for debugging, but sometimes it’s just a Unity bug. Don’t discount the possibility of needing to submit a bug report.

What version are you using? If you can reproduce the faulty effect in a minimal project, maybe we can, too.

Hi,

Ok, I found out why it wasn’t working and it was not Unity fault. My platforms have BoxCollider2D and an Platform Effector 2D. I just noticed that when using a Platform Effector 2D you have to specify the collision layer - it won’t use the one of the game object owner. So I did learn something today :wink:

2 Likes