Workshop › OutRun-style Racer › Step 27 of 44
To feel a curve, the car must know which segment it is on. segmentAt(z) gives the segment at a distance z along the
track. Our car is PLAYER_Z in front of the camera, so it is on segmentAt(position + PLAYER_Z).
```js
const PLAYER_Z = CAMERA_HEIGHT * DEPTH // how far in front of the camera the player's car is
const segmentAt = (z) => segments[Math.floor(z / SEG) % segments.length]
```PLAYER_Z is how far in front of the camera the bottom of the screen is: about 839 units.Math.floor(z / SEG) is the segment number, % segments.length wraps past the end of the track, and
segments[...] takes that element (numbers start at 0).DEPTH line write PLAYER_Z.function update() { write segmentAt, followed by an empty line.Skills: Arrays and objects
← No jumps in the curve Curves pull you outwards →