# How can I get non-player sprites to face the player?

**URL:** <https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113>\
**Category:** Help\
**Tags:** game\
**Created:** [April 15, 2022, 6:00pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113 "2022-04-15T18:00:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grapefruit19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/grapefruit19/32/6076_2.png) [@Grapefruit19](https://forum.makecode.com/u/Grapefruit19)\
**Post date:** [April 15, 2022, 6:00pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113/1 "2022-04-15T18:00:38Z")

</div>

I am currently working on a wave-based zombie survival game for a final project. I have been successful in getting the enemy sprites to follow the player and avoid obstacles to a degree. My main issue at the moment is getting the enemies to face the player at all times (or at least the enemies in view). Would anyone know of any extensions or example codes that would show how to do this??

---

<div class="post-metadata">

**Author:** ![personalnote](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/personalnote/32/31359_2.png) [@personalnote](https://forum.makecode.com/u/personalnote)\
**Post date:** [April 18, 2022, 5:20pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113/2 "2022-04-18T17:20:26Z")

</div>

character animation extension. Very helpful for animations.

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [April 18, 2022, 5:20pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113/3 "2022-04-18T17:20:55Z")

</div>

You could use the location of the sprites so for example  
if zombie y \< player y  
zombie look down

Thats all I can do for you rn but if you need further help with it tell me!

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [April 18, 2022, 5:59pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113/4 "2022-04-18T17:59:17Z")

</div>

You can use this code:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b0219a2d9e3ed3d7e6c68b02f53c4f407460a8a6.png)

> **[test](https://arcade.makecode.com/39301-59026-27924-57194)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

So for every enemy it detects if it is to the left or to the right of the player, then changes its image accordingly. Also, if you want to optimize it more, use something like the sprite utils extension’s (paste into the search bar in the extensions page: [https://github.com/jwunderl/arcade-sprite-util](https://github.com/jwunderl/arcade-sprite-util)) for "array of sprites of kind within “(maybe 80??)” pixels of " instead of "array of sprites of kind . Also, if you have left and right animations, use the timer extension’s "for action “action” at most every ", then put the animations under it.

---

<div class="post-metadata">

**Author:** ![Grapefruit19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/grapefruit19/32/6076_2.png) [@Grapefruit19](https://forum.makecode.com/u/Grapefruit19)\
**Post date:** [April 19, 2022, 5:52pm UTC](https://forum.makecode.com/t/how-can-i-get-non-player-sprites-to-face-the-player/13113/5 "2022-04-19T17:52:11Z")

</div>

Also here is a link to the game, the code is currently very messy and I’m waiting to optimize, but I will put comments on the blocks I’m having issues with. [https://makecode.com/\_AD027Ud83HXX](https://makecode.com/_AD027Ud83HXX)
