Add minimum distance to enable following
This commit is contained in:
parent
f340e8114d
commit
7c7144527c
@ -157,24 +157,28 @@ export class Player extends Character {
|
|||||||
|
|
||||||
if (activeEvents.get(UserInputEvent.Interact)) {
|
if (activeEvents.get(UserInputEvent.Interact)) {
|
||||||
const sortedPlayers = Array.from(this.scene.MapPlayersByKey.values()).sort((p1, p2) => {
|
const sortedPlayers = Array.from(this.scene.MapPlayersByKey.values()).sort((p1, p2) => {
|
||||||
const distToP1 = Math.pow(p1.x - this.x, 2) + Math.pow(p1.y - this.y, 2);
|
const sdistToP1 = Math.pow(p1.x - this.x, 2) + Math.pow(p1.y - this.y, 2);
|
||||||
const distToP2 = Math.pow(p2.x - this.x, 2) + Math.pow(p2.y - this.y, 2);
|
const sdistToP2 = Math.pow(p2.x - this.x, 2) + Math.pow(p2.y - this.y, 2);
|
||||||
if (distToP1 > distToP2) {
|
if (sdistToP1 > sdistToP2) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (distToP1 < distToP2) {
|
} else if (sdistToP1 < sdistToP2) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const minFollowDist = 10000;
|
||||||
if (typeof sortedPlayers !== "undefined" && sortedPlayers.length > 0) {
|
if (typeof sortedPlayers !== "undefined" && sortedPlayers.length > 0) {
|
||||||
|
const sdist = Math.pow(sortedPlayers[0].x - this.x, 2) + Math.pow(sortedPlayers[0].y - this.y, 2);
|
||||||
|
if (sdist < minFollowDist) {
|
||||||
this.follow = {
|
this.follow = {
|
||||||
followPlayer: sortedPlayers[0],
|
followPlayer: sortedPlayers[0],
|
||||||
direction: this.previousDirection,
|
direction: this.previousDirection,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
activeEvents.get(UserInputEvent.MoveUp) ||
|
activeEvents.get(UserInputEvent.MoveUp) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user