diff --git a/common/npc.js b/common/npc.js index 7799bd8..392277d 100644 --- a/common/npc.js +++ b/common/npc.js @@ -14,8 +14,10 @@ class NPC { this.immortal = true; + this.posOff = { x: 0, y: 0 }; + this.serverProps = [ - 'type', 'pos','vel','you','immortal' + 'type', 'pos', 'vel', 'you', 'immortal', 'posOff' ]; } handleTick(game) { @@ -28,8 +30,13 @@ class NPC { i++; } - this.vel.x += (rEntity.pos.x - this.pos.x) * 0.0002; - this.vel.y += (rEntity.pos.y - this.pos.y) * 0.0002; + if (Math.random() < 0.01) { + this.posOff.x = (Math.random() * 50 - 25) * entities.length; + this.posOff.y = (Math.random() * 50 - 25) * entities.length; + } + + this.vel.x += (rEntity.pos.x - this.pos.x + this.posOff.x) * 0.0002; + this.vel.y += (rEntity.pos.y - this.pos.y + this.posOff.y) * 0.0002; this.vel.x *= 0.995; this.vel.y *= 0.995;