Collision physics with some objects, not others

Hi Guys,

I’ve just been trying to work out how to have my Player bang into things (Rigidbody physics) but not be knocked about when hit with a projectile (OnTriggerEnter). A quick scoot through various forums and whatnots shows there’s quite a lot of people asking the question and there’s a real range of answer, all based on differing requirements of the outcomes – and it’s a little bewildering. In the end I actually created a tiny raycast that destroys the object before collision (Stopping the collision taking effect).

Is this the right way to do it? Should I be using a more elegant solution? I’m new to Unity and so I don’t know what’s working because I’m creating a huge, inelegant workaround, and what works because it’s a good way of doing it.

First, assign different layers to the objects you do not want to collide with each other. You do this by selecting your object and using this menu in the inspector:

You can create new layers, as the default ones may not be enough.
Now, go to Edit > Project Settings > Physics. At the bottom of the physics settings, you have the “Layer Collision Matrix”. You can use the checkboxes to determine which layers collide with other layers.

Looking at your question, however, it looks like you may only need to check “Is Trigger” on the colliders of your bullets. This will make them not collide with anything, and only call “OnTriggerEnter” when they intersect another collider.