How to shoot a shot that doesn't collide with the player firing?

Take something like a tanks game with a small turret in the middle of a large tank so the barrel is always inside the tank’s collider. When the tank fires, the shell launches within its bounds. How do we ensure it can’t collide with the tank in 2D physics but can collide with everything else until it’s past the tank’s collider (ricochets back)? I’m looking for something like a Physics2D.IgnoreCollision as described for 3D physics in the manual -

…but there doesn’t appear to be a way to exclude certain rigidbody interactions in 2D unless I’m missing something.

You could use a trigger.

How so? OnTriggerExit?

You can set the physics layer for tank shells to separate layers e.g. playerShells and enemyShells. Then exclude the shells from hitting the tank.

Or you can delay the enabling of the shell’s collider or change the collision layer with a scripted time delay.

Another option is to set the instantiation point of the shell outside of the barrels collider, using an empty game object as the transform.

Yes, you could have the projectile as a trigger, then on exit barrel, turn projectile into a collision.

Thanks for the suggestions.So the solution is awkward workarounds, huh? Really odd that this feature isn’t in. Physics2D is really basic!

A lot of solutions for unique problems are work arounds.
You must get crafty!

The easiest solution is to put the shells on separate layers that don’t hit their own side.

That’s a near impossibility, or crazy complication. I have ‘tanks’ that shoot ‘shells’. I want the shells to hit tanks, naturally. If I move the player to a different layer so it isn’t hit by its ‘shells’, it won’t get hit by any shells. So then I have the player’s shells on a different layer to other shells, okay. But then I need two layers for every single player, whether bot or player. That’s crazy!!

The inability to exclude certain collisions makes many game types pretty much impossible with Unity’s 2D implementation. Space Invaders may be okay, but anything more complex is screwed. Really not sure what to do now. My game was going along swimmingly until just now when some types of long shots were coming out rotated, which I finally tracked down to a self collision. Given no ETA on a fix for this feature, should I spend my time refactoring the entire game to 3D and take the performance hit? Or launch every shot from a circle around the player where it can’t self collide instead of where it should be?