Making a character move in a straight line back and forth using AI controller

I am trying to make a character move in a level back and forth in a straight line using the AI controller. I have added a nav mesh volume that shows which area the person is allowed to walk in but rn, it’s very random and I want to make it a straight direction. How can i do this?

This is what I have rn. I think i just need to modify this somehow but not sure how.

This should get you… going!

You shouldn’t use Tick for this.

On begin play you save your pawns location to a variable (Initial Position)
Then you take the direction the character is facing (forward vector) and multiply by the distance you want it to move and add the initial position.

When the move to location node fires it is getting the goal location from the select node and since the bool coming from flip flop node by default is false it will return the Checkpoints location. The next time flip flop node fires the “Is A” bool will return true and the select node will pick Initial position to be used for Move To Location node.

But keep in mind that this doesn’t check if it’s a valid location.

Yay! It works. Im still a bit confused what is happening in the code though

Is there a way to have it aware of surroundings and have it move around like an actual person and have more AI qualities.

Of course! I suggest watching this AI tutorial. I found it to be very useful.

which video talks about randomizing player movement. I don’t want the AI to just follow me.