# How to make a projectile from an enemy aim directly at a player?

**URL:** <https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485>\
**Category:** Help\
**Tags:** game\
**Created:** [January 30, 2024, 7:53pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485 "2024-01-30T19:53:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Redsword](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsword/32/12843_2.png) [@Redsword](https://forum.makecode.com/u/Redsword)\
**Post date:** [January 30, 2024, 7:53pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/1 "2024-01-30T19:53:56Z")

</div>

Like, shooting a projectile that always aims at the player? Tried doing this, but it just shoots weirdly and doesn’t work.

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [January 30, 2024, 9:07pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/2 "2024-01-30T21:07:02Z")

</div>

Something something Pythagorean theorem.  
If you make the y speed the y distance between the shooter and the… recipient? And the same with the X, then the projectile will work. You might have to mess with - and +, it has been a while since I have done this. I will go look at old code if you need a better explanation and a few screenshots.

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [January 30, 2024, 10:28pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/3 "2024-01-30T22:28:24Z")

</div>

Actually, I think there is a way easier way to do this. After looking at my old code, I actually gave up on the math and used the Follow ( ) with speed () block on a temporary invisible sprite. Then I set two variables to the X and the Y speed of the invisible object, deleted the invisible object, and then set the bullet’s X and Y speed to the two variables from before. Hope this helps!

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [January 30, 2024, 11:01pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/4 "2024-01-30T23:01:20Z")

</div>

The [`arcade-sprite-util`](https://github.com/jwunderl/arcade-sprite-util) extension has blocks to help you do that:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/6/69d1d88b1638ca109363d9bfed9a6f37de98fcc3.png)

---

<div class="post-metadata">

**Author:** ![Catz\_N\_Coffee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/catz_n_coffee/32/15323_2.png) [@Catz\_N\_Coffee](https://forum.makecode.com/u/Catz_N_Coffee)\
**Post date:** [September 16, 2024, 5:33pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/5 "2024-09-16T17:33:55Z")

</div>

could you give me an example?

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [September 17, 2024, 3:27am UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/6 "2024-09-17T03:27:08Z")

</div>

Of course! [Here](https://arcade.makecode.com/S11313-37385-73884-91458) is the simple way I was talking about. The main thing to note is the Wait 100 block after setting the sprite to follow. This gives the sprite time to start following the player sprite and you will notice that even with a Wait 50 there instead the sprites will often be slightly off of where they should be going. If this wait is not desirable you can just use the Sprite Util extension talked about above!

---

<div class="post-metadata">

**Author:** ![Catz\_N\_Coffee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/catz_n_coffee/32/15323_2.png) [@Catz\_N\_Coffee](https://forum.makecode.com/u/Catz_N_Coffee)\
**Post date:** [September 19, 2024, 3:12am UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/7 "2024-09-19T03:12:02Z")

</div>

thank you so much! i tried the Pythaga-somthing theorem technique though,

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [September 20, 2024, 4:08am UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/8 "2024-09-20T04:08:16Z")

</div>

Did you figure it out? I’ve always been too lazy to do the math and stuff, but I suppose once you do it once it can be copied between projects so I’m very interested if you did get it working!

---

<div class="post-metadata">

**Author:** ![Catz\_N\_Coffee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/catz_n_coffee/32/15323_2.png) [@Catz\_N\_Coffee](https://forum.makecode.com/u/Catz_N_Coffee)\
**Post date:** [October 8, 2024, 5:15pm UTC](https://forum.makecode.com/t/how-to-make-a-projectile-from-an-enemy-aim-directly-at-a-player/26485/9 "2024-10-08T17:15:31Z")

</div>

i did
