AI Character move away from pawn but stop after some distance.

Hello brilliant ue devs.

I am pretty new to blueprints and lack a lot of common knowledge with using them. Currently, I’m creating a simple game for a school project and have run into a roadblock. I have been trying to create a script that will make the ai character move away from the player but stop after some distance. I figured out how to make it chase the player when in range and how to make it run away but I can’t figure how to do this specific action.

For more context about what I am trying to create: imagine an ai character walking in a straight path but when the player comes within a certain range the ai will move away and always keep a certain distance from the player., then it will remain on the path.

I am using Unreal Engine 4.27 and would appreciate any help, especially screenshots of bp scripts. Thanks a ton!

Hard to recommend anything specific since we don’t know how you’re doing things atm. Perhaps you could take advantage of Pawn Sensing, If the AI detects Player Pawn, they run away in the opposite direction:

You get to control some params here.

If no Pawn is detected, the AI can return to whatever other routine you set up.


You could use a sphere overlap on the player pawn to send the AI away in a very similar way instead of the Pawn Sensing comp.

I was using pawn sensing and ai perception originally but couldn’t figure the right script out. This is pretty much exactly what I was looking for, thanks a lot!

1 Like