Workshop › Pac-Man-style Maze Chase › Step 37 of 42
A scared ghost is slow (16 frames a tile, half the player's speed) and has no target: at each crossing it picks one of its allowed directions at random.
```js
if (g.scared) return 16
if (g.scared) {
g.dir = options[Math.floor(Math.random() * options.length)]
return
}
```Math.random() * options.length is a number from 0 up to the number of options; Math.floor makes it a whole index.ghostFrames, write the scared line.chooseGhost, between the dead-end block and const t = target(g), write the random block.Skills: Game states
← Power pellets work Eat a scared ghost →