AI to react to projectiles flying past them?

Currently my AI will react to projectiles “exploding” next to them, and also to seeing a player, hearing footsteps etc.

However I still am not accounting for projectiles that fly past them. This leads to some odd gameplay where NPC’s will just ignore a bullet flying past their head.

The MakeNoise() function i assume is not appropriate for this. Calling it every tick from projectiles seems like overkill. Anyone know of a better approach?


off the top of my head here’s how I’d do it:

  • make a timer when a weapon is shot in the rough direction of the AI character, with the estimated time to hit
  • if the weapon hits, clear the timer
  • if the weapon didn’t hit, the timer notifies the AI

Maybe with each shot, you could also send out a trace along the same line, but with a wider extent. If the wide-extent trace hits an AI pawn, but the zero-extent trace (or narrow-extent trace) bullet missed it, then trigger the AI reaction.

the issue with a wider extent is that you need to make it wide enough to add enough ‘tolerance’ for the AI to hear it from a certain distance, and at the same time a wide extent can hit anything from other enemies to the ground to other obstacles etc.
personally I can see that failing more often than not, and I’d resort to an angle-based (to check the general direction of the AI) plus impact-distance-based (to check if the hit impact is close to the enemy or if it’s past him) calculations

Battlefield has a mechanic for suppression when projectiles fly near the player. I wonder ho they have implemented their system.

Chosker, there are pros and cons to both approaches. You can also do a TraceActors with an extent, which has the possibly of returning a lot of actors. And if there are a lot of people shooting at the same time, this could get prohibitively expensive. But it would catch everyone within a certain distance of the bullet.

If you wanted to do an angle-based detection, then you would probably want to make the angle narrower the farther the AI is from the shooter. Otherwise at long distances the bullet could land 20 meters away but still be within the angle to detect as a near miss.

have a collision mesh with touch all on the ai pawn whatever radius you want
if a bullet touches, have the ai react as you like

This is a pretty nice and simple idea @tegleg. Thanks for sharing.