- Home /
Having issue with Field of view in 2D environment
Hi
I am writing a small 2d game where I have implemented field of view for the character. Basicly I am raycasting around the character to determine the mesh of the field of view and use Stencil buffer to determine what is visible within that given mesh. Everything outside that mesh is overlay-d with a darker image. The basic idea I got from this tutorial: https://www.youtube.com/watch?v=CSeUMTaNFYk only that I am using newer URP.
In the game, player can navigate in outside environment that contains small houses. Houses are basicly 2 images representing outside the house on one layer and inside on the other. Once player steps inside the house the outer layer of the house is disabled thus the inside becomes visible. Corresponding collider geometry is in place to generate corresponding field of view mesh (so that player should not be able to see through the walls, but he should be able to see through the door frame and windows.
Current solution doesn't allow me to hide parts of the characters that are outside and behind wall while player is on the inside. If I add a mask on the wall I will also be masking the characters that are on the inside.
I have added 2 images below to illustrate the issue and outlined the field of view mesh with red lines. Image when player is on the outside
Image when player is on the inside (parts of the character should be hidden behind wall but are not since they are inside field of view *
I would be grateful for any suggestion on how to approach that issue. I was already suggested to add some "no go " margin area (eg. flower beds or something) so that no character would get close to wall, but it would still produce artifacts around the doors)
I think I have come up with an idea on how to solve that issue. I will have to run some experiments, then I will keep this post updated.
Your answer
Follow this Question
Related Questions
Making a 2D Ragdoll 2 Answers
Large Image/Sprite Renderer components cause FPS drop on device 0 Answers
How to make parts of a 2D ragdoll not collide with eachother? 2 Answers
How do I render objects in an order based on their y position for 2D? 0 Answers
How do I set up my sprites/skeletons to correctly interact with isometric sorting layers? 2 Answers