# How do i detect the nearest sprite of a type?

**URL:** <https://forum.makecode.com/t/how-do-i-detect-the-nearest-sprite-of-a-type/41556>\
**Category:** Help\
**Tags:** game, extension\
**Created:** [January 16, 2026, 7:17pm UTC](https://forum.makecode.com/t/how-do-i-detect-the-nearest-sprite-of-a-type/41556 "2026-01-16T19:17:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Bilangus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bilangus/32/33219_2.png) [@Bilangus](https://forum.makecode.com/u/Bilangus)\
**Post date:** [January 16, 2026, 7:40pm UTC](https://forum.makecode.com/t/how-do-i-detect-the-nearest-sprite-of-a-type/41556/2 "2026-01-16T19:40:50Z")

</div>

Check out this topic by Luke!

> [@\[Tutorial\] Making an Enemy Follow Multiple Sprites snake](https://forum.makecode.com/t/tutorial-making-an-enemy-follow-multiple-sprites/33914):
>
> The code gathers all the player-enemy distances, sorts them in an array to find the shortest distance, then for each player sprite, compares it’s distance to the shortest distance in the array to find the closest player. This player sprite is stored in the enemy sprite data and set as a follow target. All of this happens every game update so that the enemy can register a new closest player as fast as possible. The array before being sorted. After the sort, the 52.47… distance will be…

---

_[View the full topic](https://forum.makecode.com/t/how-do-i-detect-the-nearest-sprite-of-a-type/41556)._
