fixes to NPC movement
This commit is contained in:
parent
68f90e71fb
commit
a42005712c
1 changed files with 10 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue