From 4602947942bec1d829ea263caa6723da0d55a199 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:20 -0500 Subject: [PATCH] more npc physics changes --- common/npc.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/npc.js b/common/npc.js index 392277d..ae653c8 100644 --- a/common/npc.js +++ b/common/npc.js @@ -25,14 +25,16 @@ class NPC { let rEntity, i = 0; - while ((!rEntity || rEntity.type != 'Player') && i < 100) { + while ((!rEntity || rEntity.type != 'Player' || rEntity.health <= 0) && i < 100) { rEntity = entities[Math.floor(Math.random() * entities.length)]; i++; } + let jitter = entities.filter(x => x.type == 'Player' && x && x.health > 0).length; + if (Math.random() < 0.01) { - this.posOff.x = (Math.random() * 50 - 25) * entities.length; - this.posOff.y = (Math.random() * 50 - 25) * entities.length; + this.posOff.x = (Math.random() * 50 - 25) * jitter; + this.posOff.y = (Math.random() * 50 - 25) * jitter; } this.vel.x += (rEntity.pos.x - this.pos.x + this.posOff.x) * 0.0002;