I have an AI actor which, when sensed, will chase an NPC and shoot at it. There are multiple NPC’s that the AI actor could chase but I am trying to get it to chase the first one it senses until either the AI actor forgets or the NPC actor is destroyed.
I have setup AI Perception on the AI actor and each NPC is a AI Perception Stimulus source. I have the AI actor detecting the NPC’s and it will walk to the location it sensed the NPC or shoot at it based on a random number being less (chase) or more (shoot) than 0.5
The issue I have is that as soon as the AI actor gets an update via AI Perception it will focus on this new stimulus rather than continuing to chase the original NPC.
I thought about using AI perception to get the first NPC contact and then turn the AI Perception off. I’d then use the NPC object I got from the AI Perception update so I can check it’s location periodically for an amount of time before turning AI Perception back on and letting it give me a new target to chase/shoot at.
I’m sure there is a much better/more efficient way of doing this but I’m pretty stumped so reaching out for some collective wisdom
Hello @robdav1969
I recommend to separate that logic from the senses itself and add a “Commitment Time”
Save in blackboard the current target and save also a timestamp. Use this blackboard key to trigger the chase behavior.
When you sense a new player you check the timestamp of the previous target set. If x time passed from the last target set you are able to set the target again.
This is really useful to avoid switching targets. Another example this could be useful if you make your AI to chase player by distance, is better to have a “commitment time” to avoid to keep switching between targets.
I really like the time stamp idea. I could combine time/stamp with distance and only switch if the npc is within a certain distance once the timer has expired!
I am also looking into how EQS could help but again I think I’d come up against the same issue with switching targets as I have with AI Perception.
I will use EQS for the NPC run and hide logic as it’s perfect for that and I already have a tested and working version of that which I can drop in.