- Home /
2D Whether to use a Trigger or not.
Sorry if this has been already answered, but I have been trying to figure it out desperately and couldn't find anything already.
Question: How to allow 2D objects with colliders and rigidbodies (spells) to not interact at all with NPCS, but keeps it's collider property for everything else?
Background: So to start, I am making a small rpg game, and I have create some spell prefabs, which have their own Spell script, box2dCollider, and Rigidbody2d. I am very happy with how most of my spells react with the environment. However some times I want to have objects that they can go through, or not touch (such as not touching npcs). But at the moment they knockback the npc all the same.
I tried OnTrigger2D but then figured I would need to add a bunch of cases of other stuff it can't go through.
If anyone needs to see any code, I am happy to oblige, but I am more or less asking a question of how best to approach this issue.
Answer by IndievdB · Sep 19, 2017 at 03:38 AM
You can assign your spells to one layer and your NPCs to another. Then go to Edit > Project Settings > Physics 2D Settings. Under those settings, you can alter the Layer Collision Matrix so that the spell layer and the NPC layer do not interact.
Your answer
![](https://koobas.hobune.stream/wayback/20220612135141im_/https://answers.unity.com/themes/thub/images/avi.jpg)