Best practice: multiplayer collisions

I’m creating a basic 2D top-down multiplayer battle arena space game, where guns can be placed arbitrarily on the surface of a spacecraft.

Obviously I don’t want rockets to collide with the spacecraft that’s shooting them, but I do want them to collide with everything else in the game.

One obvious way to solve this is to create a separate layer for each player (Player1, Player2 etc.), and a separate layer for each player’s rockets (Player1Rocket…). But that’s clearly not a good solution because it limits the number of players the game will support.

Any other ideas?

You are looking for Physics.IgnoreCollision.

When your bullet is instantiated, just put that above statement into the Awake() or Start() method. Or, you could create a method on your bullet such as:

public void IgnoreCollider(Collider c) {
    Physics.IgnoreCollision(c, GetComponent<Collider>());
}

and then this from whatever script you Instantiate it from:

bullet.GetComponent<BulletScript>().IgnoreCollider(GetComponent<Collider>());

Good luck! Let me know if you need anything else.