more npc physics changes

This commit is contained in:
biglyderv 2024-10-03 04:58:53 -04:00
parent 8c2649a404
commit 9f5c99e6a5
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954

View file

@ -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;