# How to detect which direction a sprite it moving?

**URL:** <https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400>\
**Category:** Help\
**Created:** [May 5, 2025, 10:33pm UTC](https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400 "2025-05-05T22:33:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gl125371](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gl125371/32/29131_2.png) [@Gl125371](https://forum.makecode.com/u/Gl125371)\
**Post date:** [May 5, 2025, 10:33pm UTC](https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400/1 "2025-05-05T22:33:37Z")

</div>

Hi, how do I make a sprite that is not user-controlled and that knows what direction it is moving? I am trying to make it face the direction it is moving and change its image accordingly.

---

<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:** [May 5, 2025, 10:52pm UTC](https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400/2 "2025-05-05T22:52:38Z")

</div>

for a simple orthographic left right up down system just check it’s vx and vy since these are also technically vectors they give both magnitude and direction (forwards or backwards on a line)

if vx is positive it’s moving right  
if vx is negative it’s moving left

if vy is positive it’s moving down  
if vy is negative it’s moving up

put these into an array of sprites of kind [insert desiredspritekind] if you want it to act for multiple different sprites of the same kind (like enemies)

using the sprite utils extension, you can also measure the velocity angle of a sprite for very precise angles  
(and it would also be more optimised code)

oops yeah richard is completely right! use character animations if you’re animating!

---

<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:** [May 5, 2025, 10:53pm UTC](https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400/3 "2025-05-05T22:53:37Z")

</div>

if you just want this information for animating sprites, then i’d recommend using the character animations extension!

---

<div class="post-metadata">

**Author:** ![Gl125371](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gl125371/32/29131_2.png) [@Gl125371](https://forum.makecode.com/u/Gl125371)\
**Post date:** [May 7, 2025, 3:58am UTC](https://forum.makecode.com/t/how-to-detect-which-direction-a-sprite-it-moving/36400/4 "2025-05-07T03:58:27Z")

</div>

Ok. Thank you!
