Workshop › Lunar Lander › Step 28 of 31
A crash that only prints "Crashed" is a letdown. The lander should burst into 24 pieces flying out in random directions.
```js
let debris
debris = []
// A burst of pieces flying out from the wreck.
for (let i = 0; i < 24; i++) {
const a = Math.random() * Math.PI * 2
const speed = 1 + Math.random() * 3
debris.push({ x: lander.x, y: lander.y, vx: Math.cos(a) * speed, vy: Math.sin(a) * speed - 2, life: 60 })
}
```a is a random direction: any angle in a full turn. speed is from 1 to 4.cos and sin turn the direction and speed into vx and vy; - 2 nudges every piece upward.let state ... write let debris.startLevel, under state = 'flying', write debris = [].touchdown, under state = 'crashed', write the comment and the for loop.Skills: Velocity and gravity, Arrays and objects
← A high score Pieces fall and fade →