4 directional movement for enemy

So I am making a top down style hack n slash and I have the player moving in only 4 directions(Up, down, left and down). What I want now is for the enemies to move in a 4 directional way as well. Honestly not sure where to start with this so any help would be appreciated :).

Thanks in advance! :smiley:

You have only 3 (reasonable) ways:

  • Implement custom CharacterMovementComponent and make sure externally requested movement vectors get axis-aligned
  • Implement custom PathFollowingComponent and axis-align movement vectors passed down to AI’s movement component
  • Implement grid-based NavigationData along with pathfinder that will generate grid-paths. If you properly generate paths the rest will just work.

Those are the proper ways. I bet there’s a trick solution for it as well, but I don’t do tricks :wink:

Cheers,

–mieszko

The only way I can imagine getting the result you seek in BP is by micro-controlling AI’s movement. I mean telling AI where to go in a straight line and once it gets there tell it again, and again, and so forth.

You should be able to get a ā€œpath objectā€ in BP, that could guide this kind of micro-managed movement.

I’m sorry but we don’t support this kind of movement for AI out of the box :confused:

No, I said I can imagine doing this in BP. But either way you’ll need to put some work in, there’s no single switch you can flip to get this behavior.

Those all sound super complicated XD how would I go about starting the setup in blueprint? I have tried to find stuff on custom character movement component in blueprints but most of the stuff is c++.

So I would need to use C++ then in order to achieve what I am looking for?

I’m willing to put in the work just trying to look where to get started. I’ll research what you suggested some more and will come back if I have questions.

Thank you for the help!

So I have been researching but am having trouble making sense of any of the 3 ways you said I could possibly achieve this.

As a super simple limiter, when you tell the AI to move, make sure that either the X or Y value on the move to is equal to your current location. That would make sure you are only moving either vertically or horizontally.

So this is what I have for AI so far. Idk if I am doing this correctly or not, but right now it will move to the play when the player passes over a trigger. Should the next step I do be to get player location and then do a break vector and then set actor location to the player?

Little update. I now have ai movement that can move randomly and then chase the player in vision but what I want to achieve now is to put points on the map and make the ai randomly move to those points but only use one axis at a time. So basically no moving diagonally.