# How to make Projectiles follow

**URL:** <https://forum.makecode.com/t/how-to-make-projectiles-follow/16391>\
**Category:** Help\
**Created:** [November 17, 2022, 8:58pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391 "2022-11-17T20:58:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 17, 2022, 8:58pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/1 "2022-11-17T20:58:18Z")

</div>

How to when i hit “A” it will follow a random enemy after 30 seconds or so it will stay at that direction and if another projectile follows the enemy but that enemy is destroyed how to make it follow another enemy

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 17, 2022, 9:04pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/2 "2022-11-17T21:04:46Z")

</div>

Alright, let me make sure I have the question right:

1. When you press A, fire a projectile
2. The projectile should follow a random enemy
3. If the enemy that the projectile is following is destroyed, start following a different enemy
4. After 30 seconds of following enemies, the projectile should stop following and fly off into the abyss

Is that right?

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 17, 2022, 9:38pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/3 "2022-11-17T21:38:51Z")

</div>

let me add one more question how can I make it only got only 4 ways (North East West South) and how can I change the direction speed in each way?

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 17, 2022, 9:38pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/4 "2022-11-17T21:38:54Z")

</div>

yes lol im sorry English is not my Native Language

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 17, 2022, 10:43pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/5 "2022-11-17T22:43:08Z")

</div>

@isoffline np! I just wanted to make sure I had all the requirements. Here is some example code for you, I added comments that explain everything:

> **[enemy follow example](https://arcade.makecode.com/S77027-43961-88496-60438)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 17, 2022, 11:28pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/6 "2022-11-17T23:28:55Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 18, 2022, 1:27am UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/7 "2022-11-18T01:27:29Z")

</div>

I’m so sorry. But how can you make it follow the closest enemy I see it only follows 1 enemy

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [November 18, 2022, 5:36pm UTC](https://forum.makecode.com/t/how-to-make-projectiles-follow/16391/8 "2022-11-18T17:36:56Z")

</div>

You could compare the absolute x and y values of the enemies centered around the projectile
