Workshop › Bomberman-style Arena › Step 11 of 42
A player on a grid should not jump from tile to tile but slide. moveTo takes one small step towards the target tile;
when it is closer than a step, it snaps onto the tile and drops the target.
```js
const SPEED = 0.1 // tiles per frame
// Step a mover towards its target tile, and drop the target once it is there.
function moveTo(m, speed) {
const dx = m.target.c - m.x
const dy = m.target.r - m.y
if (Math.abs(dx) <= speed && Math.abs(dy) <= speed) {
m.x = m.target.c
m.y = m.target.r
m.target = null
return
}
m.x += Math.sign(dx) * speed
m.y += Math.sign(dy) * speed
}
```dx, dy is how far the target is, in tiles.return leaves.Math.sign (1, -1 or 0) moves it one speed towards the target on each axis. At 0.1 a tile takes 10
frames.TOP write SPEED.keydown listener write the comment and moveTo.Skills: Game states