# Enemy follow in a maze game

**URL:** <https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152>\
**Category:** Help\
**Created:** [April 12, 2023, 7:47pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152 "2023-04-12T19:47:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bee](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bee](https://forum.makecode.com/u/bee)\
**Post date:** [April 12, 2023, 7:47pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/1 "2023-04-12T19:47:29Z")

</div>

I’m making a pacman style maze game and I want to have my enemies follow my sprite, but with more logic than the “enemy follow mysprite” block. I want them to follow the maze pathways. The “enemy follow” block just makes the enemies run into walls and get stuck in corners. Is there any way to do this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [April 12, 2023, 7:52pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/2 "2023-04-12T19:52:08Z")

</div>

Absolutely, @bee

There was a trick back in the old Shang Chi map that did something just like this:

—-

A little barrier wouldn’t stop a Ten Rings assassin. Let’s teach them to jump when something stands in their way.

* * *

► From `||scene:Scene||`, drag  
`||scene:on [sprite] of kind [Player] hits wall at [location]||` into an empty area of the workspace and change `||scene:Player||` to `||scene:Enemy||`.

► From `||sprites:Sprites||` drag `||sprites:make [mySprite] hurdle side wall||` into the empty container.

► Drag the `||variables(noclick):sprite||` value from the outer container down to replace `||variables(noclick):mySprite||`.

```blocks
scene.onHitWall(SpriteKind.Enemy, function (sprite, location) {
    sprites.wall_jump(sprite)
})

```

(You obviously don’t need to make them jump at a wall, you can have them turn around or otherwise change their velocity, instead.)

---

<div class="post-metadata">

**Author:** ![bee](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bee](https://forum.makecode.com/u/bee)\
**Post date:** [April 12, 2023, 10:54pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/3 "2023-04-12T22:54:54Z")

</div>

Thanks! This looks like it might do what I want. I can’t find the “make MySprite hurdle side wall” block. It seems to be from an extension, but I can’t figure out which one.

---

<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:** [April 12, 2023, 10:54pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/4 "2023-04-12T22:54:59Z")

</div>

The [Tilemap Path Finding](https://forum.makecode.com/t/tilemap-path-finding-a-beta/1846) extension works great for this!

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [April 12, 2023, 11:02pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/5 "2023-04-12T23:02:20Z")

</div>

or you can mak a path form your enemy to your sprite using :its a path finder

> **[GitHub - jwunderl/arcade-tilemap-a-star: a star implementation for tilemaps...](https://github.com/jwunderl/arcade-tilemap-a-star)**
>
> a star implementation for tilemaps in pxt-arcade ---beta - GitHub - jwunderl/arcade-tilemap-a-star: a star implementation for tilemaps in pxt-arcade ---beta

---

<div class="post-metadata">

**Author:** ![bee](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bee](https://forum.makecode.com/u/bee)\
**Post date:** [April 14, 2023, 10:51pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/6 "2023-04-14T22:51:38Z")

</div>

This extension is great! I"ve got the enemy to follow my sprite. But it only follows the path exactly, I can’t seem to get it to update the path. I’ve tried putting the “sprite ducks follow path” block in a game update or forever loop, but it doesn’t work. Any suggestions? [https://arcade.makecode.com/S84836-56548-19698-75495](https://arcade.makecode.com/S84836-56548-19698-75495)

---

<div class="post-metadata">

**Author:** ![Sherbet\_cookie](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Sherbet\_cookie](https://forum.makecode.com/u/Sherbet_cookie)\
**Post date:** [August 21, 2023, 5:13pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/7 "2023-08-21T17:13:45Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4d939f3361904b46512efe7754752dbdaac9ec40.png)  
this extension dosent works

---

<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:** [August 21, 2023, 5:27pm UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/8 "2023-08-21T17:27:49Z")

</div>

There is a separate block “from location to location” Just put that in place of item-player and put the “sprite tilemap location” in the first and “item-player tilemap location” in the second. You probably have to keep updating the players position using a game update block.

---

<div class="post-metadata">

**Author:** ![Sherbet\_cookie](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Sherbet\_cookie](https://forum.makecode.com/u/Sherbet_cookie)\
**Post date:** [August 24, 2023, 6:33am UTC](https://forum.makecode.com/t/enemy-follow-in-a-maze-game/19152/9 "2023-08-24T06:33:37Z")

</div>

oh thanks
