Making NPC character move repeatedly

Hi all!
I need to make NPC character in a 2D game walk back and forth within certain distance from it’s initial position. (The values of how far to the left and to the right it can go are given as variables, because they can be different for different instances of the character). I also need it to start moving at random to the right or to the left at the start of the level.
So far, I’ve figured out, that I need to create character AI controller, and I created a script, that make my NPC move left or right. But where do I go from there? How to make it move repeatedly?
Here is a link to the blueprint, in case the screenshot isn’t clear. NPC Moveent posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

1 Like

You can get it working with something like this:

Instead of the “Move to Location” function, you can call AI MoveTo, which has an output pin that executes once the movement order is completed. So when the “Success” pin executes upon reaching the target location, you can call your movement logic again. Maybe add in a small delay before calling if you want the NPC to wait in between movement cycles.

Thanks! I understand the idea, but It doesn’t seem to work. Does the Nav Mesh need to exist on the level for AI Move To to work?
I was using **Move To Location **with “no pathfinding” option, because I’m making 2D game, and I don’t think I need pathfinding here - just simple back and forth movement.