# How to make sprites point at eachother

**URL:** <https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853>\
**Category:** Help\
**Tags:** game\
**Created:** [December 7, 2023, 10:08pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853 "2023-12-07T22:08:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![realMonkiemanking](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@realMonkiemanking](https://forum.makecode.com/u/realMonkiemanking)\
**Post date:** [December 7, 2023, 10:08pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/1 "2023-12-07T22:08:50Z")

</div>

I am making a game where you go around the map collecting presents and I am trying to make it where my character can point at the closest present or all of the presents in the array. But I have no idea how to do that so please help.

---

<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:** [December 8, 2023, 12:15am UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/2 "2023-12-08T00:15:17Z")

</div>

well you can do it by using the atan2 function.  
first thing ill ask is  
do you know about radians?

---

<div class="post-metadata">

**Author:** ![RobbyZero](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/robbyzero/32/17188_2.png) [@RobbyZero](https://forum.makecode.com/u/RobbyZero)\
**Post date:** [December 8, 2023, 12:15am UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/3 "2023-12-08T00:15:53Z")

</div>

I can help… maybe. Can you share it with me?

---

<div class="post-metadata">

**Author:** ![realMonkiemanking](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@realMonkiemanking](https://forum.makecode.com/u/realMonkiemanking)\
**Post date:** [December 14, 2023, 6:46pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/4 "2023-12-14T18:46:16Z")

</div>

I do not

---

<div class="post-metadata">

**Author:** ![realMonkiemanking](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@realMonkiemanking](https://forum.makecode.com/u/realMonkiemanking)\
**Post date:** [December 14, 2023, 6:47pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/5 "2023-12-14T18:47:07Z")

</div>

ye [https://arcade.makecode.com/S29907-04396-40117-67423](https://arcade.makecode.com/S29907-04396-40117-67423)

---

<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:** [December 18, 2023, 5:04pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/6 "2023-12-18T17:04:11Z")

</div>

well here is my explanation  
radians are like an angle in degrees but insted of 0° to 360° radians go from 0 to 2π  
or 0 to 6.28318530718  
now you might think that thats a weird amount. but that becuse that a radians is the point on a circle with a radius of 1  
so a radiant is the distance traveled on its circumference  
here is an example as images  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/ccedb52c3dfe6aaf24ac442fa595078171c34cb0.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/92792c8c9dd75c7ed3f980eb7a8fd0c31480c3e7.png)

since atan2() is a trig function it works with radians so to get the angle between two sprites you can do

```auto
Math.atan2(y1-y2,x1-x2)

```

and that outputs the angle in radians between two sprites  
if you want more information on radiens you can watch this video  
[https://youtu.be/cgPYLJ-s5II](https://youtu.be/cgPYLJ-s5II) (please note that i did not make this video)  
but you can use the [sprite util extension](https://github.com/jwunderl/arcade-sprite-util) and the [rotate image extension](https://github.com/robo-technical-group/pxt-arcade-image-transform) these two extension can help a lot

---

<div class="post-metadata">

**Author:** ![realMonkiemanking](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@realMonkiemanking](https://forum.makecode.com/u/realMonkiemanking)\
**Post date:** [January 29, 2024, 9:57pm UTC](https://forum.makecode.com/t/how-to-make-sprites-point-at-eachother/24853/7 "2024-01-29T21:57:53Z")

</div>

Thank you for your response it was very helpful.
