2D Collision Matrix Not Working

Hello everyone!

So I’m currently working on a 2D top down shooter project where the player is supposed to remain within the confines of the map, but the enemies can go through the boundaries. My problem is that my attempts to ignore collisions between the 2D physics layers “Enemies” and “Bounds” have proven quite unsuccessful. I have double, triple, and quadruple checked the collision matrix in the physics 2D settings to make sure I did it right, and I’m 99.99% sure that I did it correctly. I even tried to call the Physics2D.IgnoreLayerCollision( 9 , 10 , true ); function, but to no avail. Any and all help would be appreciated!

Thanks collective!

-ezshack

@EZS
So I would do this instead:

public GameObject enemy;
public GameObject barrier;

void Start() {
    Debug.LogError("Layer Of Enemies: " + enemy.layer);
    Debug.LogError("Layer Of The Barriers: " + barrier.layer);
    Physics2D.IgnoreLayerCollision(enemy.layer, barrier.layer, true);
}

This method usually guarantees you have the right layer and you only need one of each of the game object’s. Oh and for debugging I would also keep the Debug.Log messages so you can check and see if your layers were correct. Hope this helps you fix it.

@KittenSnipes Thank you for your help, it did end up helping me get where I was intending to go.

So I ended up solving the problem myself. After receiving very limited help on Unity Answers or Reddit, I eventually fiddled around enough that I got where I needed to be. I ended up needing to set the physics2d layers manually in my code then using the values I set them to in the IgnoreLayerCollision() function. I think that there is a bug with Unity’s 2D physics layers. Does anyone think I should submit a bug report?