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

Walk

What we are doing

Up (or W) walks forwards in the looking direction, Down (or S) backwards. The step is the direction's cos and sin times the speed. Walls don't stop you yet.

```js
const MOVE = 0.05 // tiles per frame

function move(dx, dy) {
  player.x += dx
  player.y += dy
}

  const forward = (keys.ArrowUp || keys.w ? 1 : 0) - (keys.ArrowDown || keys.s ? 1 : 0)
  if (forward !== 0) move(Math.cos(player.angle) * MOVE * forward, Math.sin(player.angle) * MOVE * forward)
```

What it means

Your turn

  1. Above TURN, write MOVE.
  2. Above the key listeners, write move.
  3. At the end of update, write the two walking lines.

Skills: Keyboard and mouse input, Velocity and gravity

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