Workshop › Mario-style Platformer › Step 13 of 37
Walls work like floors: move sideways first, and if that lands inside a tile, snap back to its side. Then move vertically, as before. Handling the two axes separately is the key trick of tile collisions.
```js
// Move along one axis at a time; if that ends inside a wall, snap back to the wall's edge.
function moveX(body) {
body.x += body.vx
if (!overlapsSolid(body)) return false
if (body.vx > 0) body.x = Math.floor((body.x + body.w - EPS) / TILE) * TILE - body.w
else body.x = Math.floor(body.x / TILE) * TILE + TILE
body.vx = 0
return true
}
moveX(player)
```Math.floor((x + w - EPS) / TILE) * TILE; the body's right side goes there.Math.floor(x / TILE) * TILE + TILE.true when it hit a wall, false otherwise. The enemies will use that answer to turn around.function moveY(body) { write moveX with its comment, and an empty line after it.updatePlayer, replace player.x += player.vx with moveX(player).Skills: Collision detection