I've been trying to think of good solution for a while but havent thought of one that really feels right, so I was curious to see what suggestions others would have. I'm making a 2d top down military game and I'm having trouble with how to handle bullets when an enemy is in cover. Currently, my AI can get in to cover and it will block all projectiles. But, let's say there is some thing like a barrel that an enemy is hiding behind. ideally, some bullets would collde with the barrel, and some would not. Another part of the problem is what if there is another object in between that a projectile has to pass over.
I thought about giving the projectile a height when it is first created, and then have that adjust by some constant random velocity and have that height factored in to collisions, but that could cause some outlandish issues where the projectile is missing and colliding with the ground or going over the enemy's head when it should not, and with the aiming height not being controlled by the player, this seems like it would become very frustrating. A player is going to expect the height of the game area to be mostly irrelevant because of the 2d top-down style, so using that with collisions seems wrong.
I could set a flag on the barrel itself, saying that their is an enemy taking cover behind it, and then force some projectiles to collide with the barrel and others to pass over it. Then, if an enemy was in a ducking state he would be safe from bullets. The problem I see here is complexity of the enemy talking with the barrel to set a flag to tell the physics system to allow some projectile to pass and others not, and then needing to check the enemy's state to see if he is low enough.... it just seems like a lot of communication between many different objects/systems.
So, what are some other ways this could be accomplished? Or does one of my ideas seem appropriate?