How to make AI Run Away from Player with BluePrint?

Hello guys.
I’m trying to implement an animal behaviour on my AI. Basically what I have so far is patrolling randomly between 4 points. What I wanted is, every time the AI spots the player it runs away. I wanted to be able to control that sight radius as well and make it that, in a certain range it becames aware of the player and stops patrolling but if the player gets even closer then it starts running away.
Tried to watch some tutorials online but most are made inside of the AI event graph and like that it’s seems to have conflicts with my behaviour tree so don’t work properly that’s why I wanted to do it inside of a blueprint to have a little bit more control.
Would really appreciate some guidance!
Thank you.

Trying to do it in the blueprint will conflict with the behavior tree. It will generally be better to do it in the behavior tree.

What you’ll want to do is add a few more parallel behaviors, and have entry gates on each of them. Add a property “running away” boolean and a “running away until” time, and then do something like:

  • if in running away mode, if “running away until” time is not yet expired, keep running away, else set “running away” to false (which will resume patrolling)
  • if not in running away mode, but player within sight radius, then if player is close enough, then set “running away” and “running away time”, else if player is not close enough, then stand still
  • if not in running away mode, and not in sight radius, then patrol

Hi. Thanks for replying.
Yes is something like that that I need but I don’t know exactly how to do it. Could you tell me how to implement a running away mechanic? I already have a chase machanic but don’t know how to achieve the opposite.

There are a few ways to do this, depending on game design.

You could set a number of “good hiding spots” using some kind of marker actor, and then pick a random one, or the closest one that’s not too close to the player, as your movement target.

Or you could create the vector pointing away from the player (calculate Normalized(AIPos - PlayerPos)) and multiply that by 80 meters, use the navmesh “get closest navigable point” function with that point as an argument, and run to there. Maybe add some random X/Y +/- 20 meters to make it slightly less “just run straight away.”

Both of these are reasonably straightforward, and may be good enough. If you try them, and they’re not good enough for your gameplay, then you’ll have to think a little harder about what your gameplay really requires, and attempt to modify the system to do that. Maybe there are allies they want to run to? Maybe there are resources (healing?) on the map they want to gather? Maybe there is treasure they want to guard?

i have the same question, hope know more information in here, thanks

Hey there @anonymous_user_6d66d58b. So it took me some time but I think I figure it out.
Basically what I did was some basic math:

  • I get both player and AI current location and subtract;
  • Then I normalize that value and multiply with the AI max walk speed (I put a bigger value on the max walk speed cause I wanted the AI to actually run from the player and not just walk away);
    -Then connect the result with GetRandomPointInNavigableRadius;
    -Connect that to a Black Board Vector Variable that I created to set that random value;
    With works fine for me although I still want/need to create another state (like alert state) just to make sure is the right behavior.
1 Like

Hi, I don’t find the “Event Receive Execute Ai”. Did you changed the name?\

Sorry late reply.
No, is the first thing just cut it in the middle because of the print

Thank you for posting a soltuion to this. It pairs nicely with my master AI Behavior tree for numerous NPC Types all in a single tree I been trying so many other ways and even tried using EQS for this but it didn’t give the desired results fully but your solution did thanks again :slight_smile: .