Positioning of the tracking label

Good afternoon. I am making a label for shooting an object in 3D space and I am faced with the problem that when the camera is looking in the opposite direction relative to the object, the projection vector does not give the resolution that I expect. I want to get the results as it was done in the spatial-bora-boring example.
my code looks like this:

      const positionGoal = this.navigationGoal.getWorldPosition(new Vector3());
      positionGoal.project(camera);
      positionGoal.x = ((positionGoal.x + 1) * canvas.width) / 2;
      positionGoal.y = (-(positionGoal.y - 1) * canvas.height) / 2;
      const halfSizeCanvas = new Vector2(canvas.width, canvas.height).multiplyScalar(0.5);

      const centrVec = new Vector2(positionGoal.x, positionGoal.y).sub(halfSizeCanvas);
      if (centrVec.length() > NAV_PARAM.MAX_DISTANCE_MARK) {
        const direct = centrVec.clone().normalize();
        centrVec.copy(direct.clone().multiplyScalar(NAV_PARAM.MAX_DISTANCE_MARK));
        angle = (direct.angle() / Math.PI) * 180 - 90;
        positionGoal.x = centrVec.x + halfSizeCanvas.x;
        positionGoal.y = centrVec.y + halfSizeCanvas.y;
      }

What does it look like for me:

let divider=1/Math.sqrt(positionGoal.x*positionGoal.x+positionGoal.y*positionGoal.y);
positionGoal.x = positionGoal.x*divider*10;
positionGoal.y = positionGoal.y*divider*10;

This is not the case that I described. Your solution is already being used by me. The problem is when the camera is looking in the opposite direction.

Here good direction ?

yes, can you write the full code?

/js/common.js
image

1 Like

I was referring to the complete code that relates to the task.

Thanks for the help!