# Attaching a Sprite to another Sprite

**URL:** <https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354>\
**Category:** Help\
**Created:** [March 9, 2023, 3:42am UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354 "2023-03-09T03:42:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kan/32/7193_2.png) [@Kan](https://forum.makecode.com/u/Kan)\
**Post date:** [March 9, 2023, 3:42am UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/1 "2023-03-09T03:42:57Z")

</div>

So I’m building a top-down shooter, but I want the top of the sprite to be connected to another one. This is so the entire sprite doesn’t hit a wall and only the bottom half.

 ![Screenshot 2023-03-08 20.14.32](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e8c4c2b9b694cb58eaad157b35c8d39308bfeda8.png)  
To do that I want it to follow the position of the bottom and stay above it. The thing is I don’t know how to do that and I want to keep it in blocks. Any help?

---

<div class="post-metadata">

**Author:** ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)\
**Post date:** [March 9, 2023, 4:17pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/2 "2023-03-09T16:17:43Z")

</div>

forever loop  
spriteA.x = spriteB.x ( + xOffset )  
spriteA.y = spriteB.y ( + yOffset )

---

<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:** [March 9, 2023, 4:18pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/3 "2023-03-09T16:18:43Z")

</div>

This situation kind of depends on how you are using the sprite! My solution would be to have a forever block that sets the top sprite’s position to just above the bottom one’s, but depending on how you want the two pieces to behave, that might not work.

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 9, 2023, 4:23pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/4 "2023-03-09T16:23:44Z")

</div>

you could use set x and y blocks  
heres a example of how you could do this

> **[example attached sprite](https://arcade.makecode.com/S51712-16541-17343-14881)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Kan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kan/32/7193_2.png) [@Kan](https://forum.makecode.com/u/Kan)\
**Post date:** [March 9, 2023, 5:53pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/5 "2023-03-09T17:53:33Z")

</div>

So I used your code and it worked but it would glitch back and forth when you hit a wall.  
 ![Untitled video - Made with Clipchamp](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/ed1a53afa5390cdc971f9da0ce418e7f8f389f1f.gif)

Any idea for what happening here?

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 9, 2023, 7:45pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/6 "2023-03-09T19:45:08Z")

</div>

no sorry, could you send a link to the game i could try find out

---

<div class="post-metadata">

**Author:** ![Kan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kan/32/7193_2.png) [@Kan](https://forum.makecode.com/u/Kan)\
**Post date:** [March 9, 2023, 9:38pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/7 "2023-03-09T21:38:49Z")

</div>

> **[Top-down Game](https://arcade.makecode.com/40844-68270-98858-22966)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Kan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kan/32/7193_2.png) [@Kan](https://forum.makecode.com/u/Kan)\
**Post date:** [March 10, 2023, 4:54am UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/8 "2023-03-10T04:54:33Z")

</div>

got it fixed. I just had the position set to 0,0 on a loop.

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [March 10, 2023, 5:47pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/9 "2023-03-10T17:47:14Z")

</div>

ohh okay good job, sorry i was offline and did not see the link so i couldn’t help

---

<div class="post-metadata">

**Author:** ![Sonicblaston](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sonicblaston/32/19164_2.png) [@Sonicblaston](https://forum.makecode.com/u/Sonicblaston)\
**Post date:** [March 10, 2023, 7:05pm UTC](https://forum.makecode.com/t/attaching-a-sprite-to-another-sprite/18354/10 "2023-03-10T19:05:09Z")

</div>

I don’t think you fixed it properly. I walked under a tile that was lower than the robot. Then the robot got kinda squished  
It’s kinda hard to see on the picture

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/6/687c3e51d1628cd732a13398dbd8007880433d21.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/8c63bde9bc055d78b4037abe356650dc008b33b2.png)

Just test it for yourself
