# Sprite move through tile map walls?

**URL:** <https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985>\
**Category:** Help\
**Created:** [October 20, 2020, 1:12pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985 "2020-10-20T13:12:50Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 1:12pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/1 "2020-10-20T13:12:50Z")

</div>

Is there a way to allow sprites to go through tilemap walls whilst also being able to have collisions? This could be useful if had an enemy ghost, which could go through the tilemap walls while the player couldn’t but could deal damage to the player.

I was thinking of setting the ghost’s `ghost` flag to true and checking the distance between the player and the ghost and if was less than like 16 or something that would count as a “collision”.

Any ideas?

---

<div class="post-metadata">

**Author:** ![TakeTheL08](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/takethel08/32/7018_2.png) [@TakeTheL08](https://forum.makecode.com/u/TakeTheL08)\
**Post date:** [October 20, 2020, 2:15pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/2 "2020-10-20T14:15:18Z")

</div>

Idea…  
No walls and make the player move backward if they touch a ‘wall’  
Or make some code to make it a wall only if the player is near it  
But yes your idea would be cooler  
And easier

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 2:18pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/3 "2020-10-20T14:18:08Z")

</div>

> [@TakeTheL08](#):
>
> No walls and make the player move backward if they touch a ‘wall’

That is a good idea, but the player would be able to walk halfway into a wall before I detect the tile overlap and push him back. My game also relies on the `pathfinding` extension which relies on walls too…

---

<div class="post-metadata">

**Author:** ![TakeTheL08](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/takethel08/32/7018_2.png) [@TakeTheL08](https://forum.makecode.com/u/TakeTheL08)\
**Post date:** [October 20, 2020, 2:26pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/4 "2020-10-20T14:26:53Z")

</div>

huh.  
what about my second idea?

---

<div class="post-metadata">

**Author:** ![TakeTheL08](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/takethel08/32/7018_2.png) [@TakeTheL08](https://forum.makecode.com/u/TakeTheL08)\
**Post date:** [October 20, 2020, 2:27pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/5 "2020-10-20T14:27:43Z")

</div>

also have you found someone to help me with the map box scrolling?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 2:30pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/6 "2020-10-20T14:30:36Z")

</div>

> [@TakeTheL08](#):
>
> Or make some code to make it a wall only if the player is near it

Well, if a sprite that could go through walls goes near a player that has walls around him, still would be the same.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 2:30pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/7 "2020-10-20T14:30:57Z")

</div>

Sorry, no. ☹

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 20, 2020, 2:41pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/8 "2020-10-20T14:41:33Z")

</div>

I had the same sort of issue while making Frogging Fun. I wanted the cars and logs to overlap with the player, but still be able to move through the walls. That way it gives the appearance of leaving the tilemap. If that were possible, I don’t think there is a way of locating the sprite outside the tilemap. As you mention, you could make the sprite a ghost so that it leaves, but then it doesn’t overlap the player.  
My solution was to add an extra column where the player may not move over, so that it looks like the enemy leaves the screen, when in fact it just stops at the wall. I use a on hit wall event to add the sprite to an array, and then a game update interval event to put the wall hitting sprites back to other side.

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 20, 2020, 2:45pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/9 "2020-10-20T14:45:40Z")

</div>

> [@UnsignedArduino](#):
>
> I was thinking of setting the ghost’s `ghost` flag to true and checking the distance between the player and the ghost and if was less than like 16 or something that would count as a “collision”.

I think that is reasonable to assume. The current sprite collision detection does take into account not overlapping transparent pixels, but if your sprites are all the same size and occupy most of the 16x16 space, then that shouldn’t be an issue.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 3:06pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/10 "2020-10-20T15:06:43Z")

</div>

> [@cosmoscowboy](#):
>
> I think that is reasonable to assume. The current sprite collision detection does take into account not overlapping transparent pixels, but if your sprites are all the same size and occupy most of the 16x16 space, then that shouldn’t be an issue.

Yeah, they are all 16x16 and they mostly take up the whole space. Hopefully, the player won’t notice the fact they are taking damage even though the ghost is really close but not touching. The ghosts deal lots of damage and should provide a good distraction. 😅

They should also add a distance function, like `distance between [sprite] and [sprite] in pixels`. Those functions are _humongous_ in blocks.

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 20, 2020, 4:08pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/11 "2020-10-20T16:08:26Z")

</div>

[![](https://img.youtube.com/vi/QCZ2iy45YfM/maxresdefault.jpg "MakeCode Math: Sprite Distance") ](https://www.youtube.com/watch?v=QCZ2iy45YfM)

Jacob made an interesting video explaining the distance between the two sprites, and I’m sure you know how to calculate it. What I didn’t know, is that you can have a block function return a value if you use the  
‘beta’ version of the editor. I hope they incorporate that into the main editor, as returning values is essential.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 20, 2020, 4:23pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/12 "2020-10-20T16:23:17Z")

</div>

Well, it’s already here!

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

As you can see, I’m not in `beta`.

---

<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:** [October 20, 2020, 4:48pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/13 "2020-10-20T16:48:30Z")

</div>

It’s been on our todo list for a while to separate out a flag for ghost collisions and ghost tilemap collisions. I’ll try and get it into the next release if I have time

---

<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:** [October 20, 2020, 7:03pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/14 "2020-10-20T19:03:13Z")

</div>

The amazing @jwunderl comes through with a fix!

> <https://github.com/microsoft/pxt-common-packages/pull/1190/files>

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 21, 2020, 1:38pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/15 "2020-10-21T13:38:37Z")

</div>

Yes! It’s been merged!

Just wondering - in the example @jwunderl provided, he had this link:

> **[Microsoft MakeCode Arcade](https://arcade.makecode.com/app/09cfd1c8063b0d69ce25e7703281edb2efb1b0dc-b3db6078b4#pub:_ftk7vCXPUFWF)**
>
> Develop your programming skills by quickly creating and modding retro arcade games with Blocks and JavaScript in the MakeCode editor

  
Is [arcade.makecode.com/app](http://arcade.makecode.com/app) beta beta (or something similar)? I don’t see it in [arcade.makecode.com/beta](http://arcade.makecode.com/beta).

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 21, 2020, 3:59pm UTC](https://forum.makecode.com/t/sprite-move-through-tile-map-walls/3985/16 "2020-10-21T15:59:54Z")

</div>

It’s nothing super interesting - just a one off test build, specified by the long hex values following the `/app` 🙂
