# How to enable target tracking for more then one

**URL:** <https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083>\
**Category:** Help\
**Tags:** game\
**Created:** [July 26, 2026, 6:54pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083 "2026-07-26T18:54:07Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 26, 2026, 6:54pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/1 "2026-07-26T18:54:07Z")

</div>

I’m currently making a fun plane game for school, the coding is messy as it is my first time doing this. I am currently confused on why missiles (the little things that follow your y axis) stop tracking targets after another missile spawns. If anyone can help, thank you!

> **[software dev game real MAIN - Demo Revamped Combat](https://arcade.makecode.com/S09855-40315-76675-91064)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [July 26, 2026, 9:08pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/2 "2026-07-26T21:08:58Z")

</div>

for some reason I can’t move on mobile.

---

<div class="post-metadata">

**Author:** ![CodaKnight](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codaknight/32/33491_2.png) [@CodaKnight](https://forum.makecode.com/u/CodaKnight)\
**Post date:** [July 27, 2026, 3:56am UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/3 "2026-07-27T03:56:57Z")

</div>

Looking at your code @2cool4u The problem is that **every enemy missile shares the same global variable** (`ENEMY_MISSILE`), so whenever a new missile is spawned, `ENEMY_MISSILE` is reassigned to the newest sprite. After that, all of your `forever` loops are only updating that newest missile, and the older missiles are abandoned

Specifically:

```typescript
ENEMY_MISSILE = sprites.create(...)

```

creates a new missile, but overwrites the old reference.

Then later:

```typescript
forever(function () {
    ENEMY_MISSILE.y = tracked_target_pathfind
})

```

only affects whatever missile was created most recently.

A much better approach is to update **all** tracking missiles:

```typescript
forever(function () {
    for (let missile of sprites.allOfKind(SpriteKind.tracking_missile)) {
        missile.y = tracked_target_pathfind
    }
})

```

or even better, give each missile its own tracking logic when it’s created instead of relying on one global variable.

I also noticed a couple of other things:

- The `for (let index = 0; index < 1; index++)` loops don’t do anything useful—you can just remove them and create the sprite directly.
- This loop is suspicious:

```typescript
for (let ENEMY_MISSILE2 of sprites.allOfKind(SpriteKind.tracking_missile)) {
    ENEMY_MISSILE2 = sprites.createProjectileFromSprite(...)
}

```

Assigning to `ENEMY_MISSILE2` doesn’t replace the sprite in the array—it just changes the local variable, so it probably isn’t doing what you expect.

So the issue isn’t really that you’re recreating sprites in `game.onUpdate` (you’re actually spawning them every 5 seconds). It’s mainly that you’re storing every missile in the same variable, causing only the newest missile to continue tracking.

If you’re using Blocks, you could either:

- update **all** tracking missiles in a loop (`sprites.allOfKind(...)`) instead of just `ENEMY_MISSILE`, or
- if you’re comfortable switching to JavaScript for a small part, replace the code that updates `ENEMY_MISSILE.y` with:

```typescript
for (let missile of sprites.allOfKind(SpriteKind.tracking_missile)) {
    missile.y = tracked_target_pathfind
}

```

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 27, 2026, 4:00am UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/4 "2026-07-27T04:00:23Z")

</div>

aw man 😰

i didnt test on mobile, only computer

---

<div class="post-metadata">

**Author:** ![TheEarth](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theearth/32/34579_2.png) [@TheEarth](https://forum.makecode.com/u/TheEarth)\
**Post date:** [July 27, 2026, 4:00am UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/5 "2026-07-27T04:00:35Z")

</div>

I’m on mobile u can move but the background doesn’t move so it doesn’t seem like it to prove my point move forwards while shooting with a the projectiles can’t keep up but if you just shoot they got forwards

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 27, 2026, 4:21pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/6 "2026-07-27T16:21:41Z")

</div>

> [@CodaKnight](#):
>
> ```auto
> for (let missile of sprites.allOfKind(SpriteKind.tracking_missile)) {
> missile.y = tracked_target_pathfind
> 
> ```

Thank you so much! I’ve done some work and figured out of fixes. Is there anything else i can do to better optimize code?

> **[software dev game real MAIN - Demo Revamped Combat](https://arcade.makecode.com/S09855-40315-76675-91064)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 27, 2026, 4:22pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/7 "2026-07-27T16:22:16Z")

</div>

try the missiles, they are transferred less momentum, so it’d be more obvious

---

<div class="post-metadata">

**Author:** ![YamJam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yamjam/32/29681_2.png) [@YamJam](https://forum.makecode.com/u/YamJam)\
**Post date:** [July 28, 2026, 2:03am UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/8 "2026-07-28T02:03:54Z")

</div>

ngl this is very fun

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 28, 2026, 9:03pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/9 "2026-07-28T21:03:34Z")

</div>

Thank you! I’m just trying to get mechanics working rn, hopefully soon a full pledged game will come

---

<div class="post-metadata">

**Author:** ![TheEarth](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theearth/32/34579_2.png) [@TheEarth](https://forum.makecode.com/u/TheEarth)\
**Post date:** [July 29, 2026, 2:31am UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/10 "2026-07-29T02:31:18Z")

</div>

You could check this Game thingy I made a few months ago

> **[Dogfight](https://arcade.makecode.com/53572-46217-92150-71918)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Is actually pretty good I needed to make better path finding for the ai to fight each other too

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [July 29, 2026, 2:11pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/11 "2026-07-29T14:11:47Z")

</div>

yo, this has some cool features such as rotation and the minimap, awesome work!

---

<div class="post-metadata">

**Author:** ![Enzandarojo](https://avatars.discourse-cdn.com/v4/letter/e/50afbb/32.png) [@Enzandarojo](https://forum.makecode.com/u/Enzandarojo)\
**Post date:** [July 29, 2026, 2:11pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/12 "2026-07-29T14:11:59Z")

</div>

hey you can make that the misiles face torward the jet with the oficial sprite fix extension, it would be cool!

---

<div class="post-metadata">

**Author:** ![2cool4u](https://avatars.discourse-cdn.com/v4/letter/2/ea5d25/32.png) [@2cool4u](https://forum.makecode.com/u/2cool4u)\
**Post date:** [August 14, 2026, 5:12pm UTC](https://forum.makecode.com/t/how-to-enable-target-tracking-for-more-then-one/45083/13 "2026-08-14T17:12:26Z")

</div>

Sure! Sorry for late reply btw
