Avoiding Friendly Fire (Collisions, Layers, etc)

It’s a simple question (maybe a bit broader than the other discussions in scripting) but I couldn’t find it by googling. Let’s say I’m making a multiplayer 4v4 team fps. How would I avoid damaging my own teammates? I considered putting an “enemy” tag on all enemies but since it’s multiplayer, I don’t think this will work. Another idea I had was to use layer-based collisions like so:

  • Team1 players and Team2 bullets on Layer1
  • Team1 bullets and Team2 players on Layer2

I’d still have to check which players are on which layer though. Is there any better way to do this?

The physics engine has a built-in layer matrix which you can access in Edit > Project Settings > Physics. You can read more on Layer Based Collision Detection here.