Working with collision layers in Unity

In the previous blog about hitBox collider, we have an issue: it hits the player when active

To fix it, we’ll work on collision layers

Select the HitBox gameobject and create and assign to it a new layer called SwordLayer

Do the same for Player with a PlayerLayer layer

Note: — Layer — is different from — Tag — !

Select “Yes” when asking for applying changes to children

After that, go to Edit/Project Settings/Physics2D. It will show a layer’s matrix

Uncheck the SwordLayer layer checkbox that matches the PlayerLayer. This way they won’t interact with each other.

If you notice that the “hit: Player” message still appears in console, I encourage you to fix it. It’s really easy!

--

--