# 4 directional movement for enemy

**URL:** <https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734>\
**Category:** AI\
**Tags:** unreal-engine, UE4, Blueprint, question\
**Created:** [November 17, 2015, 1:54am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734 "2015-11-17T01:54:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 17, 2015, 1:54am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/1 "2015-11-17T01:54:24Z")

</div>

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! 😃

---

<div class="post-metadata">

**Author:** ![MieszkoZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MieszkoZ](https://forums.unrealengine.com/u/MieszkoZ)\
**Post date:** [November 17, 2015, 2:50am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/2 "2015-11-17T02:50:31Z")

</div>

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 😉

Cheers,

–mieszko

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 17, 2015, 3:07am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/3 "2015-11-17T03:07:18Z")

</div>

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++.

---

<div class="post-metadata">

**Author:** ![MieszkoZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MieszkoZ](https://forums.unrealengine.com/u/MieszkoZ)\
**Post date:** [November 17, 2015, 3:48am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/4 "2015-11-17T03:48:18Z")

</div>

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 😕

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 17, 2015, 3:52am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/5 "2015-11-17T03:52:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MieszkoZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MieszkoZ](https://forums.unrealengine.com/u/MieszkoZ)\
**Post date:** [November 17, 2015, 3:55am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/6 "2015-11-17T03:55:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 17, 2015, 4:00am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/7 "2015-11-17T04:00:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 17, 2015, 6:51am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/8 "2015-11-17T06:51:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Justin.Dooley](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/justin.dooley/32/1194553_2.png) [@Justin.Dooley](https://forums.unrealengine.com/u/Justin.Dooley)\
**Post date:** [November 17, 2015, 9:55pm UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/9 "2015-11-17T21:55:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 18, 2015, 12:09am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/10 "2015-11-18T00:09:39Z")

</div>

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?

 ![67191-ai.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/7/78716921c81971b075bc54351156a39925c85984.png)

---

<div class="post-metadata">

**Author:** ![ThatGuyMiniB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThatGuyMiniB](https://forums.unrealengine.com/u/ThatGuyMiniB)\
**Post date:** [November 19, 2015, 9:46am UTC](https://forums.unrealengine.com/t/4-directional-movement-for-enemy/338734/11 "2015-11-19T09:46:55Z")

</div>

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.
