How to make a rigidbody bullet move through a platform?

my character is shooting a gun. I want the bullets to shoot up through platforms but collide when moving down. They are arcing, mortar type bullets, and I would like to tie their platform collision to their velocity in y.

I can’t do Physics2D.IgnoreCollision(c1, c2) because it will still impact at least once. I can’t set it to kinematic, because it still needs to collider with enemies. I can’t do IgnoreLayerCollision(layer1, layer2) because then bullets moving down will also be affected. I could have 2 layers, one for bullets moving up and 1 for bullets moving down. That is all I can think of.

I would like to be able to just set a layermask value on the prefab. Is there any way to make specific colliders/gameobjects ignore specific layers?

Okay, this might not be a 100% perfect answer, but how about this?

Given that bullets tend to continue moving in the same direction with essentially constant velocity, how about you go into the bullet script and start checking contact point “normals” (see Unity - Scripting API: ContactPoint2D.normal)? The “normal” is perpendicular to the point of contact, and helps you figure out the orientation of two objects that end up in a collision. If there is a particular y value on a contact point’s normal (for collisions above the object in question I believe that value is -1), you could set the rigidbody’s velocity to be exactly the same as it was in the last frame (or last FixedUpdate), hopefully enabling you to pass through ceilings.

Here’s one possible code block for how I’d go about this:

void OnCollisionEnter2D(Collision2D col)
{
     if (col.contacts[0].y == -1)
     {
          RB.velocity = previousVelocity;
     }
}

You’d need to rig up the bullet’s rigidbody as RB or change RB to whatever variable you have, and set previousVelocity somewhere like FixedUpdate. Adding gameObject tag or layer checks could also help eliminate bullets passing through enemies if the bullet came from below them.

You could also test this on CollisionStay2D as well if need be, and even check more contact points’ y value than just the first contact point.