# How to make an enemy move randomly but closer to the player

**URL:** <https://forum.makecode.com/t/how-to-make-an-enemy-move-randomly-but-closer-to-the-player/30116>\
**Category:** Help\
**Created:** [August 13, 2024, 4:27pm UTC](https://forum.makecode.com/t/how-to-make-an-enemy-move-randomly-but-closer-to-the-player/30116 "2024-08-13T16:27:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelpMeh](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@HelpMeh](https://forum.makecode.com/u/HelpMeh)\
**Post date:** [August 13, 2024, 4:27pm UTC](https://forum.makecode.com/t/how-to-make-an-enemy-move-randomly-but-closer-to-the-player/30116/1 "2024-08-13T16:27:02Z")

</div>

I am making a top-down dungeon crawler, and I have a boss that will follow the player but every once in a while it will move randomly to make the boss more unpredictable, I have this code figured out but I want it to move in the general direction of the player instead of moving in a random direction. I have like half the code figured out but idk what to do next

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/e/0/e06a7f2f635d3e130c238a33a4e760b80e02d019.png)

Btw the if statement at the top that goes out of frame is just the code that decides the proximity the player must be in in order for the boss to follow the player so dw about that.

---

<div class="post-metadata">

**Author:** ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)\
**Post date:** [August 13, 2024, 8:46pm UTC](https://forum.makecode.com/t/how-to-make-an-enemy-move-randomly-but-closer-to-the-player/30116/2 "2024-08-13T20:46:02Z")

</div>

Instead of making it follow the player, you could use the chase 0 code and add a bit of randomness to the angle of the boss to the player
