Workshop › Wolfenstein-style 3D Maze › Step 7 of 18

Stop at walls, slide along them

What we are doing

Now move asks before moving. Across and down are asked separately: walking diagonally into a wall stops only the part that would enter it, so the player slides along the wall instead of sticking to it.

```js
// Moving each axis on its own lets the player slide along a wall instead of sticking to it.
function move(dx, dy) {
  if (!blocked(player.x + dx, player.y)) player.x += dx
  if (!blocked(player.x, player.y + dy)) player.y += dy
}
```

What it means

Your turn

Replace the body of move with the two checks, and write the comment above it.

Skills: Collision detection

All steps

  1. The map
  2. The player
  3. Ceiling, floor and a loop
  4. Turn around
  5. Walk
  6. Is it a wall?
  7. Stop at walls, slide along them
  8. A ray: where it starts
  9. A ray: the grid lines
  10. A ray: walk to the wall
  11. The 3D view
  12. No fish-eye
  13. Light and shade
  14. A timer
  15. Escape!
  16. Best time
  17. Touch controls
  18. Build it yourself: run