Workshop › Zelda-style Dungeon › Step 11 of 22
An enemy closer than 4 tiles chases the hero, a little slower than you walk. It moves along whichever axis the hero is farther away on, like a Zelda enemy that only walks straight.
```js
} else {
const ex = e.x + SIZE / 2 - cx
const ey = e.y + SIZE / 2 - cy
if (Math.hypot(ex, ey) < 4 * T) {
// Close: chase the player along the longer axis.
e.dir = Math.abs(ex) > Math.abs(ey) ? [-Math.sign(ex), 0] : [0, -Math.sign(ey)]
move(e, e.dir[0] * 1.1, e.dir[1] * 1.1)
}
}
```ex, ey go from the hero's middle (cx, cy, worked out earlier in update) to the enemy's middle.ex or ey: towards the hero.In the enemy loop, after the knock-back block, add an else that chases when close.
Skills: Velocity and gravity