Workshop › Lunar Lander › Step 19 of 31
A touch is a landing only if everything is right: both feet on the pad, falling slowly, hardly drifting and nearly
upright. The limits live in one object, SAFE.
```js
const SAFE = { vy: 1.2, vx: 0.6, angle: 0.2 } // the most a landing may have
function touchdown() {
const onPad = lander.x - FEET >= pad.x1 && lander.x + FEET <= pad.x2
const gentle = lander.vy <= SAFE.vy && Math.abs(lander.vx) <= SAFE.vx && Math.abs(lander.angle) <= SAFE.angle
if (onPad && gentle) {
state = 'landed'
lander.y = pad.y - 10
return
}
state = 'crashed'
}
```onPad: the left foot is right of the pad's start and the right foot left of its end.gentle: the falling speed, the sideways speed and the tilt are all within SAFE. Math.abs ignores the sign, so
drifting left or right (and tilting either way) count the same.const FEET write the SAFE constant.touchdown with the new lines.Skills: Collision detection, Game states