CT Vaughan
CT Vaughan

Reputation: 13

Unity 2D: Why Are Collisions Being Detected Between Layers When Collisions Between The Layers Are Disabled Via The Collision Matrix?

I am working on a 2d ship combat game, and to enable the enemy ai to fire cannonballs at the player I created two empty game objects (one for each side of the enemy) with colliders attached to define the enemy's firing range and detect when the player is in this range. These are on the "Enemy Target Detection Layer", and are parented to the enemy game object, which is on the "Default" layer. There are also wood pickups scattered around the map, which the enemy can pickup by colliding with. These pickups are on the "Default" layer. The player has two hitboxes, one on the "Default" layer, and on the "Enemy Target Detection" layer. In the Layer Collision Matrix in project settings, I have unchecked the box where the "Enemy Target Detection" layer, and the "Default" layer collide, however When the firing range hitbox collides with a wood pickup the enemy is credited with wood. I have also tried unchecking all the boxes on the collision matrix as a test, and the collisions still occured in the same way as before.

This is the code that credits the enemy with wood:

private void OnTriggerEnter2D(Collider2D collision)
    {
            if (collision.CompareTag("WoodPickup"))
            {
                wood++;
            }
    }

Restarting the editor did not help, and I am lost on what else to check, so any help would be appreciated.

Thanks,

CT

Upvotes: 0

Views: 576

Answers (1)

CT Vaughan
CT Vaughan

Reputation: 13

Update: I found my issue and I feel dumb now. I am working on a 2d game and I was editing the 3d collision matrix, so if anyone else's collision matrix isn't working make sure you are on the Physics2D tab instead of the Physics tab. I thought it was odd that the game seemed to be completely ignoring the collision matrix and now I know why! Thanks for the help anyways!

Upvotes: 0

Related Questions