Hi
In the playground below, click on the ground to rotate the green cube. This will change visibility of the red cube depending on green’s fov.
In terms of code, the important bit is at the top “VisibilityController”.
FOV for NPCs is important for answering the question: can agent A see other agent B? You need to know this for
a) AI because an enemy should not shoot at the player if the enemy cannot see him
b) rendering, e.g., when player agents all face away from an enemy, he should not be visible
Why do we need this here? There is tons of examples all over the internet. But this one here works in Babylon right of the bat.
Plus if you are a bit thick as I was, you know, I knew all of this: Linear algebra for game developers ~ part 2 - Wolfire Games Blog
And yet I could not get it to work in Babylon. It turned out that I kept feeding in the mesh’s rotation vector (of axis angles) whereas I should have fed the direction vector!
The other tiny bit I missed was that the dot product returns a cosine - not an angle (yeah I know, it says it right there in the link above).
Improvements, critique, etc. welcome
Notes:
The downside of the approach is that the player is visible only if it’s origin (registration point) is visible. … [Further issue arieses] if all vertices are covered and only some central part of edges/faces is visible. (@splash27 findings)
Best wishes
Joe