# Tile based movement going through walls?

**URL:** https://forum.makecode.com/t/tile-based-movement-going-through-walls/33171
**Category:** Help
**Tags:** game
**Created:** [January 16, 2025, 6:31pm UTC](https://forum.makecode.com/t/tile-based-movement-going-through-walls/33171 "2025-01-16T18:31:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ima.notarobot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/ima.notarobot/32/26551_2.png) [@Ima.notarobot](https://forum.makecode.com/u/Ima.notarobot)
#### Post date: [January 16, 2025, 6:31pm UTC](https://forum.makecode.com/t/tile-based-movement-going-through-walls/33171/1 "2025-01-16T18:31:30Z")

</div>

I have a tile turn based game but they can go through walls because of the way they move. could I have help? Here is the game link: [https://arcade.makecode.com/S04492-47953-53637-77083](https://arcade.makecode.com/S04492-47953-53637-77083)

---

<div class="post-metadata">

### Author: ![a012](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/a012/32/24099_2.png) [@a012](https://forum.makecode.com/u/a012)
#### Post date: [August 25, 2025, 10:02pm UTC](https://forum.makecode.com/t/tile-based-movement-going-through-walls/33171/2 "2025-08-25T22:02:47Z")

</div>

The problem you’re describing — characters moving through walls in a **tile-based, turn-based game** — usually happens because your movement logic **doesn’t check collisions before moving**. In MakeCode Arcade, the physics engine only stops sprites from overlapping **if you use walls or collisions correctly**.

Here’s how to fix it:

* * *

### **1. Use `set wall at` on your tiles**

Make sure all the tiles that are “walls” have the **wall property turned on**. This lets the engine know “sprites can’t go here.”

```auto
scene.setWallAt(tile, true)

```

* * *

### **2. Move with collision checking**

Instead of just doing `sprite.x += 16` (or whatever your step size), check the tile in that direction **before moving**. Example:

```auto
function canMove(sprite: Sprite, dx: number, dy: number): boolean {
    let nextTile = scene.getTile(sprite.x + dx, sprite.y + dy)
    return !scene.tileIsWall(nextTile)
}

function moveSpriteIfCan(sprite: Sprite, dx: number, dy: number) {
    if (canMove(sprite, dx, dy)) {
        sprite.x += dx
        sprite.y += dy
    }
}

```

Then use `moveSpriteIfCan(player, 16, 0)` for right, `-16` for left, etc.

* * *

### **3. Optional: Snap to grid**

In turn-based games, it’s often better to **snap sprites to tile centers** after moving. This avoids them “slipping” through corners or rounding errors.

```auto
sprite.x = Math.round(sprite.x / 16) * 16
sprite.y = Math.round(sprite.y / 16) * 16

```

* * *

Basically, the trick is: **don’t let the sprite move blindly — always check the tile in the direction first.** Once you do that, walls actually _stop_ them. The sprite.x just means go sprites and get the sprites x axis and get the y axis and round is just the round function in Math. when I say function, I mean create a new function, and moveSpriteIfCan to write, and get a sprite parameter, then 2 number parameters that is for dx and dy and in can move, use the same parameters again, sprite, 2 number parameters which are dx and dy, then create a new variable called get tile and = to the get tile at block to the sprites x plus the dx the y for the sprite as adding it by day, then return the variable, then you are done.

---

<div class="post-metadata">

### Author: ![Ima.notarobot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/ima.notarobot/32/26551_2.png) [@Ima.notarobot](https://forum.makecode.com/u/Ima.notarobot)
#### Post date: [August 26, 2025, 2:05am UTC](https://forum.makecode.com/t/tile-based-movement-going-through-walls/33171/3 "2025-08-26T02:05:29Z")

</div>

Uh, sorry to burst your bubble, but this was a long time ago. I have already solved this problem. But thank you for putting the effort the post. I appreciate it. It makes me feel good to see that some people on the forums care a lot. ❤
