I have a scenario where an explosion occurs and I have written a custom script which finds all entities within a radius and sends them an event telling them an explosion has occurred.
Now this bit works and is fine, however the next behaviour triggered on some of those entities is to run and take cover. This is only a quick prototype so doesnt need to be brilliant behaviour, just enough to show it working. Anyway so the entity will look fo nearby cover (check for cover objects within radius) then finds the closest and runs and hides behind it, all works well.
However the problem comes in when I want to factor in the position of the current threat (i.e explosion, person attacking etc), as if an explosion happens and it is next to a cover position, I dont want to run to that cover position even if it is closer, as there is a threat there, so this needs to be factored into the steps... however I am not sure how to do that.
So just to recap here is some quick psudo steps that occur:
ExplodingGameObject
|- Send Threat Occurred event to all entities in range
EntityWithinRange
|- Scan for closest cover
|- Move to cover
However there is no way I can think of for the ExplodingGameObject to notify the EntityWithinRange object when the event occurs that it should be listed as a threat. So then you want to run to the closest cover with the most distance from the threat, and there could be multiple threats later too.
Only thing I can think of is make the send event script register the ExplodingGameObject explicitly onto the EntityWithinRange object when it does the loop and send events. However is there some best practice way to solve this? as I dont want to use global objects as there may be 100s of entities all with different threats etc (maybe not all active in the game at once).
So any advice or help would be great.