Hopefully the title is self-explanatory but some more details:
- game is in isometric perspective with the camera locked to the player but from a significant distance away, creating high likelihood of obstructions by the level and decorations occuring
- I want the player to see their character’s vision and not have these obstructions block the player’s view.
One way to achieve this might be to use raycasts from the character to hide objects (like walls or buildings) if they collide with an object on the opposite side to the camera. A slight problem there is if buildings have interiors then the rays wouldn’t necessarily hit all relevant objects. Sometimes both the interior and exterior of the building would need to visible.
I’ve seen a few videos on stencil buffers but my understanding is that this might not apply, but I will admit to not understanding them well. Any help appreciated for this newbie to game dev.
A hint i found on Reddit (yikes, i know) from someone who made a nice github with their solution.
Their idea is to pass the player position to the objects shaders, and then to get 2 differents normals : from object to player, and from object to camera. Once you have those, you can make a dot product to tell if they are in the same direction or not (>0.0 if their angle is less than 90°, <0.0 if it’s greater, 0.0 would correspond to a 90° angle). Beware, i believe it’s best to normalize both your vector to a length of 1, before using dot product if you want to get accurate results.
So once you have a negative dot product, you know both direction are opposite, so the object is between the camera and the player, and should be hidden.
On top of that, they limit that effect to a small circle around the player, to avoid making objects transparent all over the screen. You’d have to find out how to limit that effect to the field of view of the player, and i sadly have no real idea about that.
The player’s view is just another normal. If you set an angle range for how large their field of view is, and then check that the player’s normal and the vector from object to player are parallel enough, it shouldn’t be too hard.
Oh, yes quite smart and maybe also computing the distance between the player and the object, to avoid making transparent objects that are in player’s sight but very far away

