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?
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
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.