Workshop › Wolfenstein-style 3D Maze › Step 9 of 18
A ray crosses the grid lines one after another. We need two kinds of distance along the ray: how far until the next vertical line (the next column) and the next horizontal line (the next row), and how far between two such lines.
```js
// How far along the ray one whole tile across (or down) is.
const deltaX = Math.abs(1 / dx)
const deltaY = Math.abs(1 / dy)
// How far along the ray the next vertical (or horizontal) grid line is.
let nextX = (dx > 0 ? col + 1 - player.x : player.x - col) * deltaX
let nextY = (dy > 0 ? row + 1 - player.y : player.y - row) * deltaY
return { deltaX, deltaY, nextX, nextY }
```1 / dx of ray length (a slanted ray needs more). Math.abs keeps it positive.nextX: the part of a tile left until the next vertical line, times deltaX.1 / 0 is Infinity, which works out fine.Replace the return line of castRay with these lines.
Skills: Velocity and gravity
← A ray: where it starts A ray: walk to the wall →