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

No fish-eye

What we are doing

Look at a flat wall straight ahead: it bulges, taller in the middle. The side rays are longer, because they go slanted. A real eye (or camera) measures distance straight ahead, so we multiply by the cosine of the ray's angle from the middle.

```js
// The distance straight ahead, not along the ray: otherwise flat walls bulge (the fish-eye effect).
const dist = hit.dist * Math.cos(angle - player.angle)
```

What it means

Your turn

Replace the dist line with the corrected one, and write the comment above it.

Skills: 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