# Closest player to an enemie

**URL:** <https://forum.makecode.com/t/closest-player-to-an-enemie/29343>\
**Category:** Arcade\
**Created:** [June 19, 2024, 9:15pm UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343 "2024-06-19T21:15:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mega0star01](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mega0star01/32/14784_2.png) [@Mega0star01](https://forum.makecode.com/u/Mega0star01)\
**Post date:** [June 19, 2024, 9:15pm UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/1 "2024-06-19T21:15:48Z")

</div>

how do i make a sprite attack or follow the closest player, it’s for a 4 players game.

---

<div class="post-metadata">

**Author:** ![anon30657772](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon30657772](https://forum.makecode.com/u/anon30657772)\
**Post date:** [June 19, 2024, 10:08pm UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/2 "2024-06-19T22:08:23Z")

</div>

> **Here's what I did in an unfinished project to calculate the distance between sprites and to determine which one is the closest enemy to the player.**
>
> ![Find closest enemy](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/274bd451265be98dcd74358687e6bc1c3ed2b6f7.png)  
> ![Calculate sprite distance](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/d/d5b333eb1b78a60bb1011547416b686335d8192f.png)

_[This is the old project](https://arcade.makecode.com/S05002-83193-65331-98753)_ if you want to tinker with the functions.

Hope this helps! 😀

---

<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:** [June 20, 2024, 3:39am UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/3 "2024-06-20T03:39:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/0eb3866671fe8d8569f8340d82ac545cf1437d92.png)  
Sprite Utils extension is VERY useful

> **[Extensions | Awesome Arcade](https://awesome-arcade.vercel.app/extensions?q=util)**
>
> This is a list of MakeCode Arcade extensions that I find super useful (or just plain cool) in my projects.

---

<div class="post-metadata">

**Author:** ![Mega0star01](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mega0star01/32/14784_2.png) [@Mega0star01](https://forum.makecode.com/u/Mega0star01)\
**Post date:** [June 20, 2024, 3:40am UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/4 "2024-06-20T03:40:56Z")

</div>

thank you!

---

<div class="post-metadata">

**Author:** ![anon30657772](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@anon30657772](https://forum.makecode.com/u/anon30657772)\
**Post date:** [June 20, 2024, 2:45pm UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/5 "2024-06-20T14:45:34Z")

</div>

Woah 😲 those **DO** seem super useful! Thanks for sharing 😀

---

<div class="post-metadata">

**Author:** ![Mega0star01](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mega0star01/32/14784_2.png) [@Mega0star01](https://forum.makecode.com/u/Mega0star01)\
**Post date:** [June 20, 2024, 2:45pm UTC](https://forum.makecode.com/t/closest-player-to-an-enemie/29343/6 "2024-06-20T14:45:38Z")

</div>

THAAAAAANKS, i really needed this extension.
