Download

Need some advice With an AI Perception issue.

I have created an AI Guard that if it sees the player, it will do a quick distance check,
Then based off that result it will either investigate by moving to the player or start shooting at them if they are under the required distance.
Very simple stuff.

**The issue **I have is that because AI perception is only activating upon re-detecting the player, if the guard is not close enough to attack he will choose to investigate,move to the player
and not attack unless AI Perception looses sight and reacquires the player again.

**The result I want **Is for the guard to approach the player and as soon as he is under the required distance then trigger the attacking mode.

I have tried to run a tick event through a gate, that gets opened when the guard starts the investigate move to player part. So the following distance check is constantly being updated on the approach, Instead of waiting for AI perception to activate, but not had any luck getting it to work yet

Anyone got any advice or solved this in a efficient way already ?

I solved this kind of situation like so:

OnPerceptionUpdate :

  • grab the actor sensed into a variable
  • Set a looping timer calling check distance every 0.5f or any sensible time you prefer

Check distance :
When distance is under your threshold act accordingly and clear the timer

Don’t forget to clear the timer on sight lost.

Thanks . I have something similar already in place with clearing timers on lost sight. I will try this method out :slight_smile:
I have never done a looping timer before though, so I will need to research how to put this together.
I did notice there are reciveAI tick tasks for the BT, but I so far I have only managed to the the aggro range to activate one the guards moves to my location , not before :frowning:
Not experienced enough with them yet