Workshop › OutRun-style Racer › Step 29 of 44
Other cars share the road. Each is an object: its distance along the track z, its place across the road x (like
playerX) and its own speed, slower than your top speed. reset places twelve of them evenly along the track.
Nothing is drawn yet.
```js
let cars
cars = []
for (let i = 0; i < 12; i++) {
cars.push({ z: (i + 1) * (trackLength / 12), x: Math.random() * 1.2 - 0.6, speed: 40 + Math.random() * 30 })
}
```Math.random() gives a number from 0 up to (not including) 1. * 1.2 - 0.6 turns it into -0.6 to 0.6, and
40 + ... * 30 into 40 to 70.let speed write let cars.reset, under speed = 0, write the four lines that build the cars.Skills: Arrays and objects, Game states
← Curves pull you outwards Distance on a loop →