# Patrolling Enemy problem

**URL:** <https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860>\
**Category:** Blueprint\
**Tags:** unreal-engine, enemy, Blueprint, question\
**Created:** [May 10, 2023, 2:51am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860 "2023-05-10T02:51:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pmiller001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pmiller001](https://forums.unrealengine.com/u/Pmiller001)\
**Post date:** [May 10, 2023, 2:51am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/1 "2023-05-10T02:51:17Z")

</div>

Hey guys! getting into blueprints and having a lot of fun. I was trying to make a simple enemy that Patrols to the left, and to the right, until you get into their radius (collision sphere) and chases you until you get out. I’ve got the chase part working, and when you exit the enemies detection radius, they stop following you, but they dont return to their spot and begin patrolling again.  
I made a distance Variable hoping that I could change the distance that the enemy patrols.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/3/3b3e3d0ccf36686c06d5002bb274e5cedb1844b2.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/0/b807f31109b20e7a1585af29d3983aa44287dcee.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/e/6aeb68c4c69c78fd99712a382e3531305dc8dc74.jpeg)

---

<div class="post-metadata">

**Author:** ![Hdubs37](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hdubs37/32/88714_2.png) [@Hdubs37](https://forums.unrealengine.com/u/Hdubs37)\
**Post date:** [May 10, 2023, 6:38am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/2 "2023-05-10T06:38:36Z")

</div>

Hello,

I don’t really get what your distance variable stand for here ?

But why don’t you use a sequence + do once node ?

Like, when an overlapping end :  
 → first, go to your start position,  
 → then, start patroling

---

<div class="post-metadata">

**Author:** ![Pmiller001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pmiller001](https://forums.unrealengine.com/u/Pmiller001)\
**Post date:** [May 10, 2023, 7:41am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/3 "2023-05-10T07:41:38Z")

</div>

Thank you for the reply!  
So I was hoping that my distance variable would allow me to change the distance my enemy npc walked.

I tried removing the variable, and using a sequence node as well as a Do once node, and I’m not sure what I’m supposed to get here, as I’m still not getting any results unfortunately 😕

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/8/b88dfd1dce620c5249f774edb649d7123018e631.png)

---

<div class="post-metadata">

**Author:** ![Hdubs37](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hdubs37/32/88714_2.png) [@Hdubs37](https://forums.unrealengine.com/u/Hdubs37)\
**Post date:** [May 10, 2023, 7:47am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/4 "2023-05-10T07:47:41Z")

</div>

Oh no sorry, the end overlap is triggered once, not continuously, so you have to make a linear sequence.  
On component overlap end → ‘ai move to’ patrol start position - and when ‘completed’-\> do the patrol stuff

---

<div class="post-metadata">

**Author:** ![Pmiller001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pmiller001](https://forums.unrealengine.com/u/Pmiller001)\
**Post date:** [May 10, 2023, 7:54am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/5 "2023-05-10T07:54:01Z")

</div>

Its no problem!  
I think i’m having some trouble wrapping my mind around this. This is what I tried doing, and still no dice.  
Ultimately I’d like for the enemy to move to the right a few paces, and then to the left. Maybe i’m over complicating it?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/f/0ffcb39f6c9342530c9a4e7624b1661ca870799d.png)

---

<div class="post-metadata">

**Author:** ![Hdubs37](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hdubs37/32/88714_2.png) [@Hdubs37](https://forums.unrealengine.com/u/Hdubs37)\
**Post date:** [May 10, 2023, 8:02am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/6 "2023-05-10T08:02:16Z")

</div>

Ok i though you got this part already. This is what you need :

You said :  
“but they dont return to their spot and begin patrolling again”

So first, you have to store in a variable this ‘spot’ position.  
When overlap end :

1. make the character go to this spot, and after,
2. doing a loop moving to ‘the spot position + some distance to the right’,
3. When arrived there, going to the ‘spot position + some distance to the left’ and when completed go back to step 2; etc.

Before making the blueprint, you have to set the logic clear in your head first, maybe draw a logic schema, it helps a lot

---

<div class="post-metadata">

**Author:** ![Pmiller001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pmiller001](https://forums.unrealengine.com/u/Pmiller001)\
**Post date:** [May 11, 2023, 1:47pm UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/7 "2023-05-11T13:47:16Z")

</div>

Thank you for the suggestion! I didnt think to do that (making the logic clear in my head).  
This is what I’m picturing.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/9/999ff395ad6cb959fc6dec5a6fbaedef8c813184.png)

---

<div class="post-metadata">

**Author:** ![Hdubs37](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hdubs37/32/88714_2.png) [@Hdubs37](https://forums.unrealengine.com/u/Hdubs37)\
**Post date:** [May 12, 2023, 6:27am UTC](https://forums.unrealengine.com/t/patrolling-enemy-problem/1160860/8 "2023-05-12T06:27:54Z")

</div>

Yes exactly. And just add a 5th step for going to patrol the opposite direction if I understood what you wanted.  
Don’t forget to store your starting position in a variable. And now you have everything to do your blueprint 🙂 give it a try and show us
