more npc physics changes
This commit is contained in:
parent
6445115744
commit
4602947942
1 changed files with 5 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue