Make AI move away from Enemy AI

Hey Guys,

Kind of stuck on this one, I need to find the Enemies location and move away from that location. Both the Ally and Enemy are AI’s with Behavior Trees, i’m having trouble finding the enemies location.

I believe it would be something like the attached image (but I still don’t know how to “Cast To…” properly while it is an AI controller not a user controlled Character. Some help would be greatly appreciated :slight_smile:

what do you trying to cast?

Use for example GetAllActorsOfClass or setup AIPerception system to make your character find enemies by himself.

After a lot of digging around, I think I finally got to work, it probably isn’t the correct way but I think it works. I had to create an Object value in BB, then set that BB value as the actor (once I cast from the AI controller) and that seems to work so far.

Now I just need some how make the Ally_Character run away from the enemies Vector. Do you happen to know how to make a character move in the opposite direction?

(enemylocation - characterlocation).normalize() - this will be opposite direction. You can multiplybit on some random vector in cone, to randomize it.

But I think you should make it go not in opposite direction, but maybe to some cover or so.

Prevent them from changing target until they kill it or so ))
It depends on your setup.

Ok Redbox, so I sorted the move away from Enemy using EQS (which wasn’t actually as hard as I thought it was) but now my Enemies keep on switching between multiple targets and don’t keep chasing down the “closest” enemy. Any idea on how to sort this out?

here is a video :

Make them change target if one gets closer to them, E.g. It runs chases an Ally_Character then another 1 spawns closer so then it chases after that.

But in the video you can see the Enemy keeps on changing target for no reason (Got really close to one then walks away, then back towards it and repeated) I’ve set it so once it kills the closest target it resets the search for another one. (Overlap Ally > Destory Ally > Set BB Value as bool (AllyIsCloser) = False) That causes it to set AllyIsCloser and PlayerIsCloser to false.

Also i’m not sure if this issue may be happening because of “Instance Synced” is set to true for the BB Actor (Only way I could get the Casting to Ally_Character to work)

To my initial questions for making them move away from a target, I used an EQS.