I'm checking if the objects are too far from the player to be able to disable some things, I'm doing so:
const obj1 = {
x: 0,
y: 0
};
const player = {
x: 0,
y: 0
};
const sqrMagnitude = (x, y) => {
return (x * x + y * y);
};
const isAwayFromPlayer = (entity, targetEntity, distanceMax) => {
if(sqrMagnitude((targetEntity.x - entity.x), (targetEntity.y -
entity.y)) > distanceMax * distanceMax){
console.log("yes!");
}else{
console.log("no!");
}
};
awayFromPlayer(obj1, player, 250);
but when walking with the player, sometimes I approach the objects and I get the console.log("yes!")
, sometimes I move away and also I get, but it was only to work if I were away from them, I'm forgetting to do some conversion to absolute value with Math.abs for example? I remember that this is how it was when I needed some time ago, but something is not working properly.