From 9f5c99e6a577ba212ff321ac585d8e3d1d8fbb2f Mon Sep 17 00:00:00 2001 From: onezDerv Date: Thu, 3 Oct 2024 04:58:53 -0400 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;