I'm new to game development. Specifically server side. Currently I am trying to implement movement of monsters. From point A to point B.
I have used an a* pathfinding library to calculate the path to be taken but I do not know the logic on how to update the movement where the monster moves in 30 frames.
I am using javascript/node.js and currently I am doing something like:
// in game.update()
if (!monster.isMoving) {
var steps = char.getPathTo(83, 213);
steps.forEach(function (cell) {
char.move(cell[0], cell[1]);
});
}
Which of course is very wrong because it will evaluate all the movements first. So what are the possible approaches for this?
I followed this game loop:
var gameLoop = function () {
var now = Date.now()
actualTicks++
if (previousTick + tickLengthMs <= now) {
var delta = (now - previousTick) / 1000
previousTick = now
game.update(delta)
actualTicks = 0
}
if (Date.now() - previousTick < tickLengthMs - 16) {
setTimeout(gameLoop)
} else {
setImmediate(gameLoop)
}